2 Numeric Values In A Dataframe Field In R

Viewed 26

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?

1 Answers

We can use mutate_at

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