Re: [R] Read vector as multi-dimensional data in R by row

2012-07-10 Thread arun
Hi HJ,

No problem.

By changing the order of numbers in both perm and dim, you can create different 
combinations
A.K.



- Original Message -
From: "yhj...@googlemail.com" 
To: arun 
Cc: 
Sent: Tuesday, July 10, 2012 7:25 PM
Subject: Re: [R] Read vector as multi-dimensional data in R by row

Dear arun,

That code works. Thanks so much for the hints!

Best wishes,
HJ


Sent using BlackBerry® from Orange

-Original Message-
From: arun 
Date: Mon, 9 Jul 2012 22:12:03 
To: HJ YAN
Reply-To: arun 
Cc: R help
Subject: Re: [R] Read vector as multi-dimensional data in R by row

Hi,

Try this:
b1<-aperm(array(a,dim=c(5,2,2)),perm=c(2,1,3))
> b1
, , 1

 [,1] [,2] [,3] [,4] [,5]
[1,]    1    2    3    4    5
[2,]    6    7    8    9   10

, , 2

 [,1] [,2] [,3] [,4] [,5]
[1,]   11   12   13   14   15
[2,]   16   17   18   19   20

A.K.



- Original Message -
From: HJ YAN 
To: r-help@r-project.org
Cc: 
Sent: Monday, July 9, 2012 7:25 PM
Subject: [R] Read vector as multi-dimensional data in R by row

Dear R users


Say I wanted to read a vector into R as multi-dimensional array by row,
e.g.

a<-c(1:20)

> b<-array(a,dim=c(2,5,2))
> b
, , 1

     [,1] [,2] [,3] [,4] [,5]
[1,]    1    3    5    7    9
[2,]    2    4    6    8   10

, , 2

     [,1] [,2] [,3] [,4] [,5]
[1,]   11   13   15   17   19
[2,]   12   14   16   18   20


But actually I wanted...

     [,1] [,2] [,3] [,4] [,5]
[1,]    1    2    3    4    5
[2,]    6    7    8    9   10

, , 2

     [,1] [,2] [,3] [,4] [,5]
[1,]   11   12   13   14   15
[2,]   16   17   18   19   20


I checked '?array' but there is not an argument or something  like
'byrow=T' as the one in 'matrix'.

Could anyone help please?

Many thanks in advance!

HJ

    [[alternative HTML version deleted]]

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

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


Re: [R] Read vector as multi-dimensional data in R by row

2012-07-10 Thread arun
Hi,

Try this:
b1<-aperm(array(a,dim=c(5,2,2)),perm=c(2,1,3))
> b1
, , 1

 [,1] [,2] [,3] [,4] [,5]
[1,]    1    2    3    4    5
[2,]    6    7    8    9   10

, , 2

 [,1] [,2] [,3] [,4] [,5]
[1,]   11   12   13   14   15
[2,]   16   17   18   19   20

A.K.



- Original Message -
From: HJ YAN 
To: r-help@r-project.org
Cc: 
Sent: Monday, July 9, 2012 7:25 PM
Subject: [R] Read vector as multi-dimensional data in R by row

Dear R users


Say I wanted to read a vector into R as multi-dimensional array by row,
e.g.

a<-c(1:20)

> b<-array(a,dim=c(2,5,2))
> b
, , 1

     [,1] [,2] [,3] [,4] [,5]
[1,]    1    3    5    7    9
[2,]    2    4    6    8   10

, , 2

     [,1] [,2] [,3] [,4] [,5]
[1,]   11   13   15   17   19
[2,]   12   14   16   18   20


But actually I wanted...

     [,1] [,2] [,3] [,4] [,5]
[1,]    1    2    3    4    5
[2,]    6    7    8    9   10

, , 2

     [,1] [,2] [,3] [,4] [,5]
[1,]   11   12   13   14   15
[2,]   16   17   18   19   20


I checked '?array' but there is not an argument or something  like
'byrow=T' as the one in 'matrix'.

Could anyone help please?

Many thanks in advance!

HJ

    [[alternative HTML version deleted]]

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


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


[R] Read vector as multi-dimensional data in R by row

2012-07-09 Thread HJ YAN
Dear R users


Say I wanted to read a vector into R as multi-dimensional array by row,
e.g.

a<-c(1:20)

> b<-array(a,dim=c(2,5,2))
> b
, , 1

 [,1] [,2] [,3] [,4] [,5]
[1,]13579
[2,]2468   10

, , 2

 [,1] [,2] [,3] [,4] [,5]
[1,]   11   13   15   17   19
[2,]   12   14   16   18   20


But actually I wanted...

 [,1] [,2] [,3] [,4] [,5]
[1,]12345
[2,]6789   10

, , 2

 [,1] [,2] [,3] [,4] [,5]
[1,]   11   12   13   14   15
[2,]   16   17   18   19   20


I checked '?array' but there is not an argument or something  like
'byrow=T' as the one in 'matrix'.

Could anyone help please?

Many thanks in advance!

HJ

[[alternative HTML version deleted]]

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