Multiply many columns by a specific other column in R with data.table?

前端 未结 3 619
一整个雨季
一整个雨季 2020-12-05 04:21

I have a large data.table in R with several columns with dollar values. In a different column I have an inflation adjustment number. I am trying to figure out how to update

3条回答
  •  余生分开走
    2020-12-05 05:06

    Since you can use dplyr on data.tables, you could also do:

    library(dplyr)
    DT %>% mutate_each(funs(.*deflator), starts_with("inc"))
    

    Which will multiply each column of DT that starts with "inc" by the "deflator" column.

提交回复
热议问题