Re: [R] Counting the Number of Letters in a row

2011-06-10 Thread Weidong Gu
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 wrote: > Hi Abraham, > > Try > > foo <- function(x){ > x <- as.character(x) >  sapply(strsplit(x, " "), function(s) sum(nchar(s))) > } > foo(f1$key

Re: [R] Counting the Number of Letters in a row

2011-06-10 Thread Jorge Ivan Velez
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

Re: [R] Counting the Number of Letters in a row

2011-06-10 Thread Ingmar Visser
something like this: sapply(strsplit(as.character( f1$keyword), " "), function(x){sum(nchar(x))}) hth, Ingmar On Fri, Jun 10, 2011 at 6: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 <-

[R] Counting the Number of Letters in a row

2011-06-10 Thread Abraham Mathew
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