R: tidyverse: how to change the datatype of a column using least charset channels
Pipes and tidyverse are sometimes very handy. The user wants to convert one column from one type to another.
Same:
mtcars$qsec <-as.integer(mtcars$qsec)
This requires entering twice what I need. Please do not suggest the "c" command, as I find it confusing.
What would be the tidvern and magrittr% <>% way to do the same with the least amount of input? Also, if qsec is the 6th column, how can I do this by simply referencing the column position. Something like (not correct code)
mtcars %<>% mutate(as.integer,qsec)
mtcars %<>% mutate(as.integer,[[6]])
+3
userJT
source
to share
1 answer
When entering a column reference only once - the answer is
mtcars %<>% mutate_at(6, as.integer)
To refer to a column by name, a solution with one redundant column name type
mtcars %<>% mutate(qsec = as.integer(qsec))
NOTE: credit goes to users comment above
+2
userJT
source
to share