Dear all How does one convert a "non-symmetric" list to a vector? See below:> x <- list() > x[[1]] <- letters[1:5] > x[[2]] <- letters[6:10] > x[[3]] <- letters[11:12] > x[[1]] [1] "a" "b" "c" "d" "e" [[2]] [1] "f" "g" "h" "i" "j" [[3]] [1] "k" "l"> paste(x)[1] "c(\"a\", \"b\", \"c\", \"d\", \"e\")" "c(\"f\", \"g\", \"h\", \"i\", \"j\")" [3] "c(\"k\", \"l\")"> as.vector(x)[[1]] [1] "a" "b" "c" "d" "e" [[2]] [1] "f" "g" "h" "i" "j" [[3]] [1] "k" "l"> simplify2array(x)[[1]] [1] "a" "b" "c" "d" "e" [[2]] [1] "f" "g" "h" "i" "j" [[3]] [1] "k" "l" What I would need to get instead is:> letters[1:12][1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" Any ideas? Regards Liviu -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail
unlist() Michael Weylandt On Wed, Aug 10, 2011 at 2:58 PM, Liviu Andronic <landronimirc@gmail.com>wrote:> Dear all > How does one convert a "non-symmetric" list to a vector? See below: > > > x <- list() > > x[[1]] <- letters[1:5] > > x[[2]] <- letters[6:10] > > x[[3]] <- letters[11:12] > > x > [[1]] > [1] "a" "b" "c" "d" "e" > > [[2]] > [1] "f" "g" "h" "i" "j" > > [[3]] > [1] "k" "l" > > > paste(x) > [1] "c(\"a\", \"b\", \"c\", \"d\", \"e\")" "c(\"f\", \"g\", \"h\", > \"i\", \"j\")" > [3] "c(\"k\", \"l\")" > > as.vector(x) > [[1]] > [1] "a" "b" "c" "d" "e" > > [[2]] > [1] "f" "g" "h" "i" "j" > > [[3]] > [1] "k" "l" > > > simplify2array(x) > [[1]] > [1] "a" "b" "c" "d" "e" > > [[2]] > [1] "f" "g" "h" "i" "j" > > [[3]] > [1] "k" "l" > > > What I would need to get instead is: > > letters[1:12] > [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" > > Any ideas? Regards > Liviu > > > -- > Do you know how to read? > http://www.alienetworks.com/srtest.cfm > http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader > Do you know how to write? > http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail > > ______________________________________________ > R-help@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. >[[alternative HTML version deleted]]
Check function unlist(). Best, Dimitris On 8/10/2011 8:58 PM, Liviu Andronic wrote:> Dear all > How does one convert a "non-symmetric" list to a vector? See below: > >> x<- list() >> x[[1]]<- letters[1:5] >> x[[2]]<- letters[6:10] >> x[[3]]<- letters[11:12] >> x > [[1]] > [1] "a" "b" "c" "d" "e" > > [[2]] > [1] "f" "g" "h" "i" "j" > > [[3]] > [1] "k" "l" > >> paste(x) > [1] "c(\"a\", \"b\", \"c\", \"d\", \"e\")" "c(\"f\", \"g\", \"h\", > \"i\", \"j\")" > [3] "c(\"k\", \"l\")" >> as.vector(x) > [[1]] > [1] "a" "b" "c" "d" "e" > > [[2]] > [1] "f" "g" "h" "i" "j" > > [[3]] > [1] "k" "l" > >> simplify2array(x) > [[1]] > [1] "a" "b" "c" "d" "e" > > [[2]] > [1] "f" "g" "h" "i" "j" > > [[3]] > [1] "k" "l" > > > What I would need to get instead is: >> letters[1:12] > [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" > > Any ideas? Regards > Liviu > >-- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/
unlist(x) r-help-bounces@r-project.org wrote on 08/10/2011 01:58:57 PM:> [image removed] > > [R] convert 'list' to 'vector'? > > Liviu Andronic > > to: > > r-help@r-project.org Help > > 08/10/2011 02:02 PM > > Sent by: > > r-help-bounces@r-project.org > > Dear all > How does one convert a "non-symmetric" list to a vector? See below: > > > x <- list() > > x[[1]] <- letters[1:5] > > x[[2]] <- letters[6:10] > > x[[3]] <- letters[11:12] > > x > [[1]] > [1] "a" "b" "c" "d" "e" > > [[2]] > [1] "f" "g" "h" "i" "j" > > [[3]] > [1] "k" "l" > > > paste(x) > [1] "c(\"a\", \"b\", \"c\", \"d\", \"e\")" "c(\"f\", \"g\", \"h\", > \"i\", \"j\")" > [3] "c(\"k\", \"l\")" > > as.vector(x) > [[1]] > [1] "a" "b" "c" "d" "e" > > [[2]] > [1] "f" "g" "h" "i" "j" > > [[3]] > [1] "k" "l" > > > simplify2array(x) > [[1]] > [1] "a" "b" "c" "d" "e" > > [[2]] > [1] "f" "g" "h" "i" "j" > > [[3]] > [1] "k" "l" > > > What I would need to get instead is: > > letters[1:12] > [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" > > Any ideas? Regards > Liviu > > > -- > Do you know how to read? > http://www.alienetworks.com/srtest.cfm > http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader > Do you know how to write? > http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html> and provide commented, minimal, self-contained, reproducible code.[[alternative HTML version deleted]]