On Sun, 16-Aug-2009 at 10:40AM -0500, Peng Yu wrote: |> Hi, |> |> I run the following program. I thought that 'b' was a matrix. But it |> is actually not, right? Can somebody elaborate more on the type |> difference between 'b' and 'c' to help me understand it better? |> |> Why 'c' is what it is now? Why 'c' is not the transpose of what it is now? |> |> Regards, |> Peng |> |> $ Rscript split.R |> > a=array(c('a,b','c,d','e,f'),c(3)) |> > a[[1]] |> [1] "a,b" |> > a |> [1] "a,b" "c,d" "e,f" |> > b=strsplit(a,split=',') |> > b[[1]] |> [1] "a" "b" |> > b |> [[1]] |> [1] "a" "b" |> |> [[2]] |> [1] "c" "d" |> |> [[3]] |> [1] "e" "f" |> |> > c=sapply(b,function(x){x[1:2]}) |> > c |> [,1] [,2] [,3] |> [1,] "a" "c" "e" |> [2,] "b" "d" "f"
I think your question is about sapply, not strsplit. It "simplifies" and if it's going to make a matrix, it will set byrow to FALSE. HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___ Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) ..... Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ______________________________________________ R-help@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.