简体   繁体   中英

2 Numeric Values In A Dataframe Field In R

I have a dataset in R with a little under 100 columns.

Some of the columns have numeric values such as 87+3 as oppose to 90.

I have been able to update each column with the following piece of code:

library(dplyr)

new_dataframe = dataframe %>%
  rowwise() %>%
  mutate(new_value = eval(parse(text = value)))

However, I would like to be able to update a list of 60 columns in a more efficient way than simply repeating this line for each column.

Can someone help me find a more efficient way?

We can use mutate_at

library(dplyr)
dataframe %>%
      rowwise() %>%
      mutate_at(1:60, list(new_value = ~eval(parse(text = .))))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM