[prev in list] [next in list] [prev in thread] [next in thread]
List: r-help
Subject: [R] Convert two-dimensional array into a three-dimensional array.
From: "Sorkin, John" <jsorkin () som ! umaryland ! edu>
Date: 2023-12-08 22:57:45
Message-ID: DM6PR03MB504979641A471930217570CCE28AA () DM6PR03MB5049 ! namprd03 ! prod ! outlook ! com
[Download RAW message or body]
Colleagues
I want to convert a 10x2 array:
# create a 10x2 matrix.
datavals <- matrix(nrow=10,ncol=2)
datavals[,] <- rep(c(1,2),10)+c(rnorm(10),rnorm(10))
datavals
into a 10x3 array, ThreeDArray, dim(10,2,10).
The values storede in ThreeDArray's first dimensions will be the data stored in \
datavalues. ThreeDArray[i,,] <- datavals[i,]
The values storede in ThreeDArray's second dimensions will be the data stored in \
datavalues. ThreeDArray[,j,] <- datavals[,j]
The data stored in ThreeDArray[,,1] will be 1,
The data stored in ThreeDArray[,,2] will be 2.
. . .
The data stored in ThreeDArray[,,10] will be 10.
I have no idea how to code the coversion of the 10x2 matrix into a 10,2,10 array.
I may be able to acomplish my mission by coding each line of the plan described \
above, but there has to be a more efficient and elegant way to accompish my goal.
Many thanks for your help!
John
John David Sorkin M.D., Ph.D.
Professor of Medicine, University of Maryland School of Medicine;
Associate Director for Biostatistics and Informatics, Baltimore VA Medical Center \
Geriatrics Research, Education, and Clinical Center;
PI Biostatistics and Informatics Core, University of Maryland School of Medicine \
Claude D. Pepper Older Americans Independence Center;
Senior Statistician University of Maryland Center for Vascular Research;
Division of Gerontology and Paliative Care,
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
Cell phone 443-418-5382
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic