Dear all,
I'm having a few problems trying to reshape a data frame. I tried with
reshape{stats} and melt{reshape} but I was missing something. Any help is
very welcome. Please find details below:
#################################
# data in its original shape:
indiv <- rep(c("A","B"),c(10,10))
level.1 <- rpois(20, lambda=3)
covar.1 <- rlnorm(20, 3, 1)
level.2 <- rpois(20, lambda=3)
covar.2 <- rlnorm(20, 3, 1)
my.dat <- data.frame(indiv,level.1,covar.1,level.2,covar.2)
# the values of level.1 and level.2 represent the number of cases for the
particular
# combination of indiv*level*covar value
# I would like to do two things:
# 1. reshape to long reducing my.dat[,2:5] into two colums "factor" (levels=
level.1 & level.2)
# and the covariate
# 2. create one new row for each case in level.1 and level.2
# the new reshaped data.frame would should look like this:
# indiv factor covar case.id
# A level.1 4.614105 1
# A level.1 4.614105 2
# A level.2 31.064405 1
# A level.2 31.064405 2
# A level.2 31.064405 3
# A level.2 31.064405 4
# A level.1 19.185784 1
# A level.2 48.455929 1
# A level.2 48.455929 2
# A level.2 48.455929 3
# etc...
#############################
Thank you very much!!
Ahimsa
--
ahimsa campos-arceiz
www.camposarceiz.com
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.