[R] Passing vectors through a dataframe
Jeremy Clark
jeremyclarkmel at gmail.com
Thu Feb 6 16:00:18 CET 2014
Dear All,
I would like to be able to associate a list of vectors (one vector of
which is to be called later) with some other character and numeric
data. I've tried two methods:
1) I can put the vector names in quotes into the dataframe, and then
extract the vector name - but this is just a character string - which
I would then like to use to re-express the original vector, which was
defined earlier.
2) If I try to put the vectors directly into the dataframe it's not
accepted because the vectors have different lengths (and in any case
it is the name of the vector which needs to be associated with the
other data, not particular values).
Probably I'm missing something basic ? Many thanks in advance (!)
Example coding showing how far I've got is as follows:
library(gdata)
F4087 <- c(234,1234,65,34,624,345)
F4187 <- c(234,542,4523,56345,233,5654,776,4788,78768,456,8756)
F4287 <- c(3423,543,6768,867,945,3456,5634,6543,345)
rsquaredtrun <- c("R4087", "R4187", "R4287")
rsquaredtrun
rsquaredvalues <- c(0.1, 0.2, 0.3)
rsquaredvalues
dxtrunlist <- c("F4087", "F4187", "F4287")
dxtrunlist
rsquareddf <- data.frame(rsquaredtrun, rsquaredvalues, dxtrunlist)
rsquareddf
df.agg <- aggregate(rsquaredvalues ~ rsquaredvalues, rsquareddf, max)
df.agg
rsquared.max <- merge(df.agg, rsquareddf)
rsquared.max
rsquared.max2 <- drop.levels(rsquared.max)
rsquared.max2
maxr <- rsquared.max2["dxtrunlist"]
maxr
maxrr <- as.matrix(maxr)
maxrr
maxrrr <- as.vector(maxrr)
maxrrr
The question is - how can I resurrect the vector F4287 from maxrrr ??
More information about the R-help
mailing list