[R] Rearrange data.
Ritwik Sinha
ritwik.sinha at gmail.com
Thu Jul 20 04:56:32 CEST 2006
Hi,
I am trying to rearrange the following data
d.f <- data.frame(x=c(1,1,2,2), y=c(1,2,1,2), vals=c("a11", "a12",
"a21", "a22"))
to look like a table with x as the rows and y as the columns, something like
y 1 2
x
1 a11 a12
2 a21 a22
I tried doing this
funny <- function(x,y){d.f[d.f$x==x & d.f$y==y,3]}
outer(1:2,1:2, FUN="funny")
But get the error
Error in outer(1:2, 1:2, FUN = "funny") : dim<- : dims [product 4] do
not match the length of object [2]
What am I doing wrong? I am sure there are a hundred different ways of
doing this.
version
platform i486-pc-linux-gnu
arch i486
os linux-gnu
system i486, linux-gnu
status
major 2
minor 2.1
year 2005
month 12
day 20
svn rev 36812
language R
--
Ritwik Sinha
Graduate Student
Epidemiology and Biostatistics
Case Western Reserve University
http://darwin.cwru.edu/~rsinha
More information about the R-help
mailing list