0

I am loading a file to watson studio with 152 columns and I have the problem that by default it takes the string type. Is there any way to change several columns at the same time? I know I can do it column by column but 150 columns are too much.

I tried "mutate_all(~ ifelse(is.na(as.double(.x)),.x,as.double(.x)))"

It works in the preview but fails when I launch the flow with the following error:

19 Feb 2019-20:15:25+0100: Job execution started
 19 Feb 2019-20:15:32+0100: Error in ifelse(is.na(as.double(.x)), .x, as.double(.x)): object 'COLUMN1' not found
 19 Feb 2019-20:15:32+0100: Job execution ended
avariant
  • 2,234
  • 5
  • 25
  • 33
Nacho
  • 3
  • 1

1 Answers1

0

If you need to do for all the string columns, please use mutate_if instead of mutate_all()

mutate_if(is.character,as.double)

It should change all the string types to double.

So if you want to not convert any specific column you would have to do something like this, -matches() would list all columns other than specified column and would apply double conversion to only those columns.

mutate_at(vars(-matches("columnname")),funs(as.double(.)))
charles gomes
  • 2,145
  • 10
  • 15