I have got a list named "filtered", I would like to construct alist named "fdata" as following: fdata <- cbind(matrix(unlist(filtered),ncol=28), myregime) If I try names(filtered), it gives all the correct name for each vector, but if I try names(fdata), it appears "filtered[[1]]" "filtered[[2]]" ..., How can I keep the name in "fdata"? Could anyone give me some advice? -- View this message in context: http://www.nabble.com/vector-name-tf4466025.html#a12733890 Sent from the R help mailing list archive at Nabble.com.
Hi, Either of the following should work (I assume there are 28 elements in your list): fdata <- cbind(as.matrix(as.data.frame(filtered)), myregime) fdata <- cbind("colnames<-"(matrix(unlist(filtered),ncol=28), names(filtered)), myregime) --- livia <yn19832 at msn.com> wrote:> > I have got a list named "filtered", I would like to construct alist named > "fdata" as following: > > fdata <- cbind(matrix(unlist(filtered),ncol=28), myregime) > > If I try names(filtered), it gives all the correct name for each vector, > but > if I try names(fdata), it appears "filtered[[1]]" "filtered[[2]]" ..., > > How can I keep the name in "fdata"? Could anyone give me some advice? > -- > View this message in context: > http://www.nabble.com/vector-name-tf4466025.html#a12733890 > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. >____________________________________________________________________________________ Luggage? GPS? Comic books?
livia wrote:> I have got a list named "filtered", I would like to construct alist named > "fdata" as following: > > fdata <- cbind(matrix(unlist(filtered),ncol=28), myregime) > > If I try names(filtered), it gives all the correct name for each vector, but > if I try names(fdata), it appears "filtered[[1]]" "filtered[[2]]" ..., > > How can I keep the name in "fdata"? Could anyone give me some advice? >You don't tell us quite enough about your data, but: This would appear to giva a matrix, not a list? Did you perchance intend do.call("cbind", c(filtered, list(myregime)) or maybe just data.frame(filtered, myregime) or as.matrix(data.frame(filtered, myregime)) -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
Seemingly Similar Threads
- probelem of function inside function
- Variable variables using R ... e.g., looping over data frames with a numeric separator
- Obtaining the internal integer codes of a factor XXXX
- problem in compiling openh323
- try (nls stops unexpectedly because of chol2inv error