Dear R-helper,
Is there possible to make this array:
> a <- array(1:12, c(4, 3))
> a
[,1] [,2] [,3]
[1,] 1 5 9
[2,] 2 6 10
[3,] 3 7 11
[4,] 4 8 12
>
like:
c(1,5,9)
c(2,6,10)
c(3,7,11)
c(4,8,12)
Thank you very much in advance.
Regards,
Muhammad Subianto
Is this what you want?> split(a, row(a))$"1" [1] 1 5 9 $"2" [1] 2 6 10 $"3" [1] 3 7 11 $"4" [1] 4 8 12 Andy> From: Muhammad Subianto > > Dear R-helper, > > Is there possible to make this array: > > a <- array(1:12, c(4, 3)) > > a > [,1] [,2] [,3] > [1,] 1 5 9 > [2,] 2 6 10 > [3,] 3 7 11 > [4,] 4 8 12 > > > > like: > c(1,5,9) > c(2,6,10) > c(3,7,11) > c(4,8,12) > > Thank you very much in advance. > Regards, > Muhammad Subianto > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > > >
Look at ?assign, one possible answer is shown in the examples. Modified for
your example:
for (i in 1:nrow(a)) {
nam <- paste("r",i, sep=".")
assign(nam, a[i,])
}
would give you four separate objects r.1 to r.4 containing the 4 vectors.
Not sure if that's exactly what you wanted though.
Norm
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Muhammad Subianto
Sent: Wednesday, May 18, 2005 7:18 AM
To: r-help at stat.math.ethz.ch
Subject: [R] How to convert array to c()
Dear R-helper,
Is there possible to make this array:
> a <- array(1:12, c(4, 3))
> a
[,1] [,2] [,3]
[1,] 1 5 9
[2,] 2 6 10
[3,] 3 7 11
[4,] 4 8 12
>
like:
c(1,5,9)
c(2,6,10)
c(3,7,11)
c(4,8,12)
Thank you very much in advance.
Regards,
Muhammad Subianto
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
How about? p1<-a[1,] p1 [1] 1 5 9 p2<-a[2,]> p2[1] 2 6 10 p3<-a[3,]> p3[1] 3 7 11 p4<-a[4,]> p4[1] 4 8 12 Jia ----- Original Message ----- From: "Muhammad Subianto" <subianto@gmail.com> To: <r-help@stat.math.ethz.ch> Sent: Wednesday, May 18, 2005 10:18 AM Subject: [R] How to convert array to c()> Dear R-helper, > > Is there possible to make this array: > > a <- array(1:12, c(4, 3)) > > a > [,1] [,2] [,3] > [1,] 1 5 9 > [2,] 2 6 10 > [3,] 3 7 11 > [4,] 4 8 12 > > > > like: > c(1,5,9) > c(2,6,10) > c(3,7,11) > c(4,8,12) > > Thank you very much in advance. > Regards, > Muhammad Subianto > > ______________________________________________ > R-help@stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide!http://www.R-project.org/posting-guide.html>[[alternative HTML version deleted]]