Hi Ista,
one way could be:

ncharacters<-unlist(lapply(x,function(x)nchar(gsub(' ','',x))))
ncharacters



________________________________
From: Ista Zahn <iz...@psych.rochester.edu>
To: r-help@r-project.org
Sent: Friday, December 12, 2008 10:31:10 AM
Subject: [R] character count

Dear list,
I have a variable that consists of typed responses. I wish to compute
a variable equal to the number of characters in the original variable.
For example:

> x <- c("convert this to 32 because it has 32 characters", "this one has 22 
> characters", "12 characters")

[Some magic function here]

> x
[1] 32 22 12

Any ideas?

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



      
        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to