[R] indexing a particular element in a list of vectors

Simon Blomberg Simon.Blomberg at anu.edu.au
Thu Oct 16 06:38:02 CEST 2003


How about:

lst <- list(c("a", "b", "c"), c("d", "e", "f"))

> sapply(lst, function (x) x[1])
[1] "a" "d"

Cheers,

Simon.

Simon Blomberg, PhD
Depression & Anxiety Consumer Research Unit
Centre for Mental Health Research
Australian National University
http://www.anu.edu.au/cmhr/
Simon.Blomberg at anu.edu.au  +61 (2) 6125 3379


> -----Original Message-----
> From: Scott Norton [mailto:nortonsm at verizon.net]
> Sent: Thursday, 16 October 2003 1:58 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] indexing a particular element in a list of vectors
> 
> 
> I have a "list" of character vectors.  I'm trying to see if 
> there is a way
> (in a single line, without a loop) to pull out the first 
> element of all the
> vectors contained in the list.
> 
>  
> 
> listOfVectors[1:length(listOfVectors][1]
> 
>  
> 
> doesn't work.
> 
>  
> 
> ==========================
> 
> If you want more details..
> 
> Here is my listOfVectors which is called "uuu"
> 
> > uuu[order(uuu)]
> 
> [[1]]
> 
> [1] "pt1pg"      "multi.expr"
> 
>  
> 
> [[2]]
> 
> [1] "1ng"        "ml"         "fluor.expr"
> 
>  
> 
> [[3]]
> 
> [1] "1pg"        "ml"         "fluor.expr"
> 
>  
> 
> [[4]]
> 
> [1] "10ng"       "ml"         "fluor.expr"
> 
>  
> 
> [[5]]
> 
> [1] "10pg"       "ml"         "fluor.expr"
> 
>  
> 
> I'm basically interested in getting the following elements:
> 
> "pt1pg", "1ng", "1pg", etc. as a list (or character vector)
> 
>  
> 
> Note, this might have an obvious solution but I claim Newbie status!
> 
>  
> 
> Thanks in advance!
> 
> -Scott
> 
>  
> 
>  
> 
> Scott Norton, Ph.D.
> 
> Engineering Manager
> 
> Nanoplex Technologies, Inc.
> 
> 2375 Garcia Ave.
> 
> Mountain View, CA 94043
> 
> www.nanoplextech.com
> 
>  
> 
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>




More information about the R-help mailing list