[R] What is the returned type of strsplit?

Peng Yu pengyu.ut at gmail.com
Sun Aug 16 17:40:10 CEST 2009


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"
>




More information about the R-help mailing list