[R] Odp: character count
petr.pikal at precheza.cz
Fri Dec 12 20:23:13 CET 2008
Ok, I knew somebody come with regex solution. My regex skills are limited
so I do not use it very often.
r-help-bounces at r-project.org napsal dne 12.12.2008 17:03:38:
> On Fri, Dec 12, 2008 at 11:00 AM, Petr PIKAL <petr.pikal at precheza.cz>
> > Hi
> > r-help-bounces at r-project.org napsal dne 12.12.2008 16:31:10:
> >> 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
> >> For example:
> >> > x <- c("convert this to 32 because it has 32 characters", "this one
> > has 22
> >> characters", "12 characters")
> >> [Some magic function here]
> > If you consider space as a character then
> > nchar(x)
> > gives you the result.
> > If not so such construction can do it
> > unlist(lapply(lapply(strsplit(x, " "), paste, collapse=""), nchar))
> or perhaps:
> x <- "abc def"
> nchar(gsub(" ", "", x)) # 6
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help