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

______________________________________________
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.

Reply via email to