sum two columns in R

前端 未结 6 1659
情书的邮戳
情书的邮戳 2020-12-03 14:00

I feel a bit embarrassed as I am trying to add two columns in R to get the product.

I have tried

sum(col1,col2)

but this returns

6条回答
  •  醉梦人生
    2020-12-03 14:49

    You can use a for loop:

    for (i in 1:nrow(df)) {
       df$col3[i] <- df$col1[i] + df$col2[i]
    }
    

提交回复
热议问题