Efficient multiplication of columns in a data frame

后端 未结 4 1508
南方客
南方客 2020-12-09 20:56

I have a large data frame in which I am multiplying two columns together to get another column. At first I was running a for-loop, like so:

for(i in 1:nrow(d         


        
4条回答
  •  醉话见心
    2020-12-09 21:21

    As Blue Magister said in comments,

    df$new_column <- df$column1 * df$column2
    

    should work just fine. Of course we can never know for sure if we don't have an example of the data.

提交回复
热议问题