Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. for(i in 1:nrow(df)){
  2.  
  3. df$new_column[i] <- df$column1[i] * df$column2[i]
  4.  
  5. }
  6.  
  7. new_df <- ddply(df, .(column1,column2), transform, new_column = column1 * column2)
  8. # but this is taking forever
  9.  
  10. df$new_column <- df$column1 * df$column2
  11.  
  12. df <- transform(df, new = column1 * column2)
  13.  
  14. df <- within(df, new <- column1 * column2)
  15.  
  16. library(data.table)
  17. DT <- data.table(df)
  18. DT[ , new := column1 * column2]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement