How to convert certain columns only to numeric?

前端 未结 4 1439
误落风尘
误落风尘 2020-12-11 18:25

How can I convert certain columns only in a data frame to numeric?

For instance, I have this data frame:

structure(list(airport = c(         


        
4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-11 19:00

    Using dplyr:

    library(dplyr)
    df %>% 
      mutate_at(vars(ws, wd, humidity), as.numeric)
    
    # A tibble: 2 x 5
    airport xdate         ws    wd humidity
                    
    1 EGLL    2016-07-28    6.  237.      68.
    2 EGLL    2016-07-31    5.  299.      55.
    

提交回复
热议问题