Removing Whitespace From a Whole Data Frame in R

后端 未结 10 607
孤街浪徒
孤街浪徒 2020-12-05 03:01

I\'ve been trying to remove the white space that I have in a data frame (using R). The data frame is large (>1gb) and has multiple columns that contains whi

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 03:40

    Picking up on Fremzy and Mielniczuk, I came to the following solution:

    data.frame(lapply(df, function(x) if(class(x)=="character") trimws(x) else(x)), stringsAsFactors=F)
    

    It works for mixed numeric/charactert dataframes manipulates only character-columns.

提交回复
热议问题