Skip to content
Prev 296496 / 398498 Next

Convert 2-dim array to 3-dim array

Hi Dave,

I tested the "as.array".? It gives a different dimension when compared to "array"

set.seed(1)
datE<-data.frame(A=rnorm(30,0.5))
myArr=as.array(unlist(datE),dim=c(5,2,3))
???????? A1????????? A2????????? A3????????? A4????????? A5????????? A6 
-0.12645381? 0.68364332 -0.33562861? 2.09528080? 0.82950777 -0.32046838 
???????? A7????????? A8????????? A9???????? A10???????? A11???????? A12 
?0.98742905? 1.23832471? 1.07578135? 0.19461161? 2.01178117? 0.88984324 
??????? A13???????? A14???????? A15???????? A16???????? A17???????? A18 
-0.12124058 -1.71469989? 1.62493092? 0.45506639? 0.48380974? 1.44383621 
??????? A19???????? A20???????? A21???????? A22???????? A23???????? A24 
?1.32122120? 1.09390132? 1.41897737? 1.28213630? 0.57456498 -1.48935170 
??????? A25???????? A26???????? A27???????? A28???????? A29???????? A30 
?1.11982575? 0.44387126? 0.34420449 -0.97075238? 0.02184994? 0.91794156
[1] TRUE
[1] 30
, , 1

?????????? [,1]?????? [,2]
[1,] -0.1264538 -0.3204684
[2,]? 0.6836433? 0.9874291
[3,] -0.3356286? 1.2383247
[4,]? 2.0952808? 1.0757814
[5,]? 0.8295078? 0.1946116

, , 2

?????????? [,1]????? [,2]
[1,]? 2.0117812 0.4550664
[2,]? 0.8898432 0.4838097
[3,] -0.1212406 1.4438362
[4,] -1.7146999 1.3212212
[5,]? 1.6249309 1.0939013

, , 3

????????? [,1]??????? [,2]
[1,]? 1.418977? 0.44387126
[2,]? 1.282136? 0.34420449
[3,]? 0.574565 -0.97075238
[4,] -1.489352? 0.02184994
[5,]? 1.119826? 0.91794156
[1] 5 2 3


A.K.




----- Original Message -----
From: David Winsemius <dwinsemius at comcast.net>
To: David Zastrau <davidz at tzi.de>
Cc: r-help at r-project.org
Sent: Monday, June 4, 2012 10:45 AM
Subject: Re: [R] Convert 2-dim array to 3-dim array
On Jun 4, 2012, at 5:08 AM, David Zastrau wrote:

            
No.? that is not the problem.
A dataframe is a list structure while both array and matrix are expecting the first argument to be an atomic vector. Try this (although it is a blind guess because you have not provided the structure of 'dat'

myArr = as.array( unlist(dat), dim = c(12,100,3))

--David.
David Winsemius, MD
West Hartford, CT

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