El 22/2/2017, a las 3:39, William Michels <wjm1 at caa.columbia.edu> escribi?:
Hi Jos? (and Rolf),
It's not entirely clear what type of 'whitespace' you're referring to,
but if you're using read.table() or read.csv() to create your
dataframe in the first place, setting 'strip.white = TRUE' will remove
leading and trailing whitespace 'from unquoted character fields
(numeric fields are always stripped).'
On 2/21/17, Rolf Turner <r.turner at auckland.ac.nz> wrote:
On 22/02/17 12:51, Jos? Luis Aguilar wrote:
Hi all,
i have a dataframe with 34 columns and 1534 observations.
In some columns I have strings with spaces, i want remove the space.
Is there a function that removes whitespace from the entire dataframe?
I use gsub but I would need some function to automate this.
Something like
X <- as.data.frame(lapply(X,function(x){gsub(" ","",x)}))
Untested, since you provide no reproducible example (despite being told
by the posting guide to do so).
I do not know what my idea will do to numeric columns or to factors.
However it should give you at least a start.
cheers,
Rolf Turner
--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276