0

I have a data frame with variables that have words in the rows, as well as variables that have numbers in the rows. The problem is that all of the variables are the character class, including the variables that have numbers in the rows. How do I use as.numeric() if I am only trying to apply it to a select number of variables and not all of them in the data frame?

Thanks

  • 3
    provide with a reproducible problem so that we can help – Mustufain May 03 '18 at 18:40
  • 2
    `mutate_at( dtfrm, vars( ...comma-delimited list of column names...), as.numeric)`, where `mutate_at` and `vars` are both found in the `dplyr` package. – Artem Sokolov May 03 '18 at 18:44
  • Each column can have only one class. Maybe you need to transform to wide format to separate the variables, https://stackoverflow.com/questions/5890584/how-to-reshape-data-from-long-to-wide-format after which `type.convert(as.character(x))` will convert numbers to numbers, etc. – Frank May 03 '18 at 18:45
  • @ArtemSokolov that worked perfectly. Thank you for your help. – Winston Willett May 03 '18 at 18:47

0 Answers0