[R] First elements of a list.
Jacques VESLOT
jacques.veslot at good.ibl.fr
Tue Aug 29 16:24:38 CEST 2006
> sapply(a, "[", 1)
[1] "John" "Jane" "koda" "gunner"
> sapply(a, "[", 2)
[1] "Smith" "Doe" NA NA
-------------------------------------------------------------------
Jacques VESLOT
CNRS UMR 8090
I.B.L (2ème étage)
1 rue du Professeur Calmette
B.P. 245
59019 Lille Cedex
Tel : 33 (0)3.20.87.10.44
Fax : 33 (0)3.20.87.10.31
http://www-good.ibl.fr
-------------------------------------------------------------------
cory a écrit :
> Suppose I have the following list:
>
> a <- strsplit(c("John;Smith", "Jane;Doe", "koda", "gunner"), ";")
>
> I want to get to these two vectors without looping...
>
> firstNames: c("John", "Jane", "koda", "gunner")
> lastNames: c("Jane", "Doe", NA, NA)
>
> Thanks
>
> cn
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>
More information about the R-help
mailing list