Re: [R] Sum of Numeric Values in a DF Column

2016-04-18 Thread Burhan ul haq
Dear Gunter / Heiberger, Thanks for the help. This is what I was looking for: > ... and here is a non-dplyr rsolution: > >> z <-gsub("[^[:digit:]]"," ",dd$Lower) > >> sapply(strsplit(z," +"),function(x)sum(as.numeric(x),na.rm=TRUE)) > [1] 105 67 60 100 80 And that would explain, why one coul

Re: [R] Sum of Numeric Values in a DF Column

2016-04-18 Thread Bert Gunter
... and a slightly more efficient non-dplyr 1-liner: > sapply(strsplit(dd$Lower,"[^[:digit:]]"), function(x)sum(as.numeric(x), na.rm=TRUE)) [1] 105 67 60 100 80 Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Op

Re: [R] Sum of Numeric Values in a DF Column

2016-04-18 Thread Bert Gunter
... and here is a non-dplyr rsolution: > z <-gsub("[^[:digit:]]"," ",dd$Lower) > sapply(strsplit(z," +"),function(x)sum(as.numeric(x),na.rm=TRUE)) [1] 105 67 60 100 80 Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it

Re: [R] Sum of Numeric Values in a DF Column

2016-04-18 Thread David Winsemius
> On Apr 18, 2016, at 9:48 AM, Burhan ul haq wrote: > > Hi, > > I request help with the following: > > INPUT: A data frame where column "Lower" is a character containing numeric > values (different count or occurrences of numeric values in each row, > mostly 2) > >> dput(dd) > structure(list(

Re: [R] Sum of Numeric Values in a DF Column

2016-04-18 Thread Richard M. Heiberger
## Continuing with your data AA <- stringr::str_extract_all(dd[[2]],"[[:digit:]]+") BB <- lapply(AA, as.numeric) ## I think you are looking for one of the following two expressions sum(unlist(BB)) sapply(BB, sum) On Mon, Apr 18, 2016 at 12:48 PM, Burhan ul haq wrote: > Hi, > > I request help wi