Apply a function to all the elements of a data frame

后端 未结 2 1444
迷失自我
迷失自我 2021-02-01 23:45

I am trying to apply some transformations to all the elements in a dataframe.

When using the regular apply functions, I get a matrix back and not a dataframe. Is there a

相关标签:
2条回答
  • 2021-02-02 00:04

    Here's a way using dplyr:

    library(dplyr)
    df  %>% mutate_each(funs(tolower))
    
    0 讨论(0)
  • 2021-02-02 00:16

    We can use lapply and assign it back to 'df'

    df[] <- lapply(df, tolower)
    

    The [] preserves the same structure as the original dataset. Using apply convert it to a matrix and that is not recommended.

    0 讨论(0)
提交回复
热议问题