我有以下数据帧:
df1
factory DC `tariff springtouw`
<chr> <chr> <dbl>
1 Poznan Bismarck 3000
2 Poznan Houston 3000
3 Poznan Memphis 2400
4 Poznan Albany 1000
5 Poznan Seattle 3500df2
Som_Product pallets kosten
duikscooter 379312 37932
yoga 75651 226
springtouw 1162413 9687 #
stoel 1300512 3252
blender 1400148 2917 我想将df1的3500乘以df2的9687,并将df2中的值附加到#的位置。
这样的代码: df2$kostenspringtouw,<- df1$tariff springtouw5,3 * df2$pallets3,2
可能的输出
output
df2
Som_Product pallets kosten
duikscooter 379312 37932
yoga 75651 226
springtouw 1162413 9687 33904500
stoel 1300512 3252
blender 1400148 2917 发布于 2021-05-11 03:15:20
索引应该是行/列索引或属性,当我们提取作为vector的列时,它没有行/列属性,即它只是一个1维向量,可以用单个整数值进行索引,以在索引指定的位置提取该元素
df2['springtouw', 'kosten'] <- df1$`tariff springtouw`[5] * df2$pallets[3]-output
df2
# Som_Product pallets kosten
#duikscooter 379312 37932
#yoga 75651 226
#springtouw 1162413 9687 33904500
#stoel 1300512 3252
#blender 1400148 2917 数据
df1 <- structure(list(factory = c("Poznan", "Poznan", "Poznan", "Poznan",
"Poznan"), DC = c("Bismarck", "Houston", "Memphis", "Albany",
"Seattle"), `tariff springtouw` = c(3000L, 3000L, 2400L, 1000L,
3500L)), class = "data.frame", row.names = c("1", "2", "3", "4",
"5"))
df2 <- structure(list(Som_Product = c(379312L, 75651L, 1162413L, 1300512L,
1400148L), pallets = c(37932L, 226L, 9687L, 3252L, 2917L), kosten = c("",
"", "", "", "")), row.names = c("duikscooter", "yoga", "springtouw",
"stoel", "blender"), class = "data.frame")https://stackoverflow.com/questions/67476387
复制相似问题