以数据作为输入:
如果stock1和stock2列中有一个列的值为com_num列,那么如何检查它们
dframe <- data.frame(
com = c("col1","em","col1","em"), com_num = c(3.1,2.1,2.1,4.1),
stock1 = c(1,0,1,1), stock2 = c(1,1,0,1)
)下面是一个预期结果的示例
dframe_ex <- data.frame(
com = c("col1","em","col1","em"), com_num = c(3.1,2.1,2.1,4.1),
stock1 = c(3.1,0,2.1,4.1), stock2 = c(3.1,2.1,0,4.1)
)
dframe_ex
com com_num stock1 stock2
1 col1 3.1 3.1 3.1
2 em 2.1 0.0 2.1
3 col1 2.1 2.1 0.0
4 em 4.1 4.1 4.1发布于 2019-02-16 03:16:59
另一个base R选项
dframe[, 3:4] <- dframe[, 3:4] * dframe[, 2]
dframe
# com com_num stock1 stock2
#1 col1 3.1 3.1 3.1
#2 em 2.1 0.0 2.1
#3 col1 2.1 2.1 0.0
#4 em 4.1 4.1 4.1 https://stackoverflow.com/questions/54715497
复制相似问题