[R] Using the output of strsplit

Peter Alspach Peter.Alspach at plantandfood.co.nz
Mon Jan 18 23:06:59 CET 2010


Tena koe Jim

You could use unlist and matrix.  For example:

> tempList
[[1]]
[1] "a" "A"

[[2]]
[1] "b" "B"

[[3]]
[1] "c" "C"

> unlist(tempList)
[1] "a" "A" "b" "B" "c" "C"
> matrix(unlist(tempList), nrow=3)
     [,1] [,2]
[1,] "a"  "B" 
[2,] "A"  "c" 
[3,] "b"  "C" 
> matrix(unlist(tempList), nrow=3, byrow=T)
     [,1] [,2]
[1,] "a"  "A" 
[2,] "b"  "B" 
[3,] "c"  "C" 
> matrix(unlist(tempList), nrow=3, byrow=T)[,1]
[1] "a" "b" "c"

HTH ....

Peter Alspach  

> -----Original Message-----
> From: r-help-bounces at r-project.org 
> [mailto:r-help-bounces at r-project.org] On Behalf Of James Rome
> Sent: Tuesday, 19 January 2010 10:49 a.m.
> To: r-help at r-project.org
> Subject: [R] Using the output of strsplit
> 
> I successfully combined my data frames, and am now on my next hurdle.
> 
> I had combined the data and quarter, and used tapply to count 
> the entries for each unique date/quarter pair.
> ar= tapply(ewrgnd$gw, list(ewrgnd$dq), sum)   #for each date/quarter
> combination sums the gw (which are all 1)
> dq=row.names(ar)
> spl=strsplit(dq)
> But I need to split them back into the separate date and 
> quarter. So I used strsplit(), and get
> > spl
> [[1]]
> [1] "2009-01-01" "60"       
> 
> [[2]]
> [1] "2009-01-01" "61"       
> 
> [[3]]
> [1] "2009-01-01" "62"       
> 
> [[4]]
> [1] "2009-01-01" "63"       
> 
> [[5]]
> [1] "2009-01-01" "68"       
> . . .
> 
> But lists throw me. I want to get separate vectors of the 
> date and quarter out of my list. All the things I have seen 
> extract rows from the list. I need to extract columns.
> 
> Thanks list,
> Jim Rome
> 
> ______________________________________________
> 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.
> 



More information about the R-help mailing list