Apply a function to all the elements of a data frame

后端 未结 2 1453
迷失自我
迷失自我 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: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.

提交回复
热议问题