Hi all,
Given the following,
> xx
[[1]]
V1 V2 V3
[1,] 1 2 3
[2,] 4 5 6
[3,] 7 8 9
[[2]]
V1 V2 V3
[1,]10 11 12
[2,]13 14 15
[3,]16 17 18
[[3]]
V1 V2 V3
[1,]19 20 21
[2,]22 23 24
[3,]25 26 27
how do i extract elements in each file so that after transpose, it looks
something like the following;
1
10
19
2
11
20
3
12
21
and so on..
Thanks..
--
Muhammad Rahiz | Doctoral Student in Regional Climate Modeling
Climate Research Laboratory, School of Geography & the Environment
Oxford University Centre for the Environment
South Parks Road, Oxford, OX1 3QY, United Kingdom
Tel: +44 (0)1865-285194 Mobile: +44 (0)7854-625974
Email: muhammad.rahiz at ouce.ox.ac.uk
If I understand, you can try this: array(do.call(rbind, xx), c(3, 3, 3)) On Wed, Dec 30, 2009 at 11:45 AM, Muhammad Rahiz <muhammad.rahiz at ouce.ox.ac.uk> wrote:> Hi all, > > Given the following, > >> xx > [[1]] > ? ?V1 V2 V3 > [1,] ?1 ?2 ?3 > [2,] ?4 ?5 ?6 > [3,] ?7 ?8 ?9 > [[2]] > ? ?V1 V2 V3 > [1,]10 11 ?12 > [2,]13 14 ?15 > [3,]16 17 ?18 > > [[3]] > ? ?V1 V2 V3 > [1,]19 20 ?21 > [2,]22 23 ?24 > [3,]25 26 ?27 > > how do i extract elements in each file so that after transpose, it looks > something like the following; > > 1 > 10 > 19 > > 2 > 11 > 20 > > 3 > 12 > 21 > > and so on.. > > Thanks.. > > > > -- > Muhammad Rahiz ?| ?Doctoral Student in Regional Climate Modeling > > Climate Research Laboratory, School of Geography & the Environment > Oxford University Centre for the Environment > South Parks Road, Oxford, OX1 3QY, United Kingdom Tel: +44 (0)1865-285194 > ?Mobile: +44 (0)7854-625974 > Email: muhammad.rahiz at ouce.ox.ac.uk > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
Hi:
An alternative is the following:
# This regenerates your dataset:
xx <- list(matrix(1:9, nrow = 3, byrow = TRUE),
matrix(10:18, nrow = 3, byrow = TRUE),
matrix(19:27, nrow = 3, byrow = TRUE))
# Flatten matrix elements of each component into vectors:
xxf <- lapply(xx, function(x) {y <- t(x); dim(y) <- NULL; y})
# rbind them into a matrix:
do.call(rbind, xxf)
# If you prefer the result as a long vector, then
as.vector(do.call(rbind, xxf))
Results:> do.call(rbind, xxf)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,] 1 2 3 4 5 6 7 8 9
[2,] 10 11 12 13 14 15 16 17 18
[3,] 19 20 21 22 23 24 25 26 27
> as.vector(do.call(rbind, xxf))
[1] 1 10 19 2 11 20 3 12 21 4 13 22 5 14 23 6 15 24 7 16 25 8 17
26 9
[26] 18 27
HTH,
Dennis
On Wed, Dec 30, 2009 at 5:45 AM, Muhammad Rahiz <
muhammad.rahiz@ouce.ox.ac.uk> wrote:
> Hi all,
>
> Given the following,
>
> > xx
> [[1]]
> V1 V2 V3
> [1,] 1 2 3
> [2,] 4 5 6
> [3,] 7 8 9
> [[2]]
> V1 V2 V3
> [1,]10 11 12
> [2,]13 14 15
> [3,]16 17 18
>
> [[3]]
> V1 V2 V3
> [1,]19 20 21
> [2,]22 23 24
> [3,]25 26 27
>
> how do i extract elements in each file so that after transpose, it looks
> something like the following;
>
> 1
> 10
> 19
>
> 2
> 11
> 20
>
> 3
> 12
> 21
>
> and so on..
>
> Thanks..
>
>
>
> --
> Muhammad Rahiz | Doctoral Student in Regional Climate Modeling
>
> Climate Research Laboratory, School of Geography & the Environment
> Oxford University Centre for the Environment
> South Parks Road, Oxford, OX1 3QY, United Kingdom Tel: +44 (0)1865-285194
> Mobile: +44 (0)7854-625974
> Email: muhammad.rahiz@ouce.ox.ac.uk
>
>
> ______________________________________________
> 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.
>
[[alternative HTML version deleted]]