An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110610/68103a64/attachment.pl>
Counting the Number of Letters in a row
4 messages · Abraham Mathew, Ingmar Visser, Jorge Ivan Velez +1 more
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110610/04e18e3d/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110610/c2bb03e7/attachment.pl>
Is this what you want? sapply(sapply(strsplit(as.character(f1$keyword),' '),nchar),sum) Weidong Gu On Fri, Jun 10, 2011 at 1:25 PM, Jorge Ivan Velez
<jorgeivanvelez at gmail.com> wrote:
Hi Abraham,
Try
foo <- function(x){
x <- as.character(x)
?sapply(strsplit(x, " "), function(s) sum(nchar(s)))
}
foo(f1$keyword)
HTH,
Jorge
On Fri, Jun 10, 2011 at 12:48 PM, Abraham Mathew <> wrote:
I'm trying to find the total number of letters in a row of a data frame.
Let's say I have the following data frame.
f1 <- data.frame(keyword=c("I live in Denver", I live in Kansas City, MO",
"Pizza is good"))
The following function gives me the number of characters in each string.
So for "I live in Denver", I get 1, 4, 2, and 6. However, I want to know
the
total
number of characters (13).
sapply(strsplit(as.character(f1$keyword), " "), nchar)
Thanks,
Abraham
? ? ? ?[[alternative HTML version deleted]]
______________________________________________ R-help at 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 at 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.