我的数据如下:
datas6=structure(list(Exp = c("BA", "CI", "CE", "DE"), Var1 = c(0L,
0L, 0L, 0L), Var2 = c(0L, 0L, 1L, 0L), Var3 = c(0L, 1L, 1L, 0L
), Var4 = c(1L, 1L, 1L, 1L), Freq = c("6", "2", "7", "5")), .Names = c("Exp",
"Var1", "Var2", "Var3", "Var4", "Freq"), row.names = c(NA, 4L
), class = "data.frame")
这是一个基本问题,我很抱歉,无法通过datas6 [6]找到从datas6 [2]乘以datas6 [5]的方法这样的伪代码:
datas6[2:5]=as.numeric(datas6[2:5])*as.numeric(datas6[6])
返回错误:
Error: object (list) can not be converted automatically into a type 'double'
也试过这个:
new_df <- ddply(datas6, (datas6[2:5]), transform, new_column = as.numeric(datas6[2:5])*as.numeric(datas6[6]))
不起作用:Error in UseMethod("as.quoted"
)
非常感谢。
答案 0 :(得分:1)
我们可以通过
来做到这一点datas6[2:5] <- datas6[2:5] * as.numeric(datas6[,6])
datas6[2:5]
# Var1 Var2 Var3 Var4
#1 0 0 0 6
#2 0 0 2 2
#3 0 7 7 7
#4 0 0 0 5