[R] Extract every 2 element for a list which are not equal in length
Mohammad Tanvir Ahamed
mashranga at yahoo.com
Tue Mar 8 01:47:21 CET 2016
Hi,
a <- c(1:5)b <- c(1:3)
c <- 1
d <- 5
e <- list(a,b,c,d)
# To extract every 1st element
lapply(e,"[[",1)
## Out-put
[[1]]
[1] 1
[[2]]
[1] 1
[[3]]
[1] 1
[[4]]
[1] 5
#To extract every 2nd element (Need help in this case)
lapply(e,"[[",2)
## Expected outcome
[[1]]
[1] 2
[[2]]
[1] 2
[[3]]
[1] NA
[[4]]
[1] NA
Any help will be appreciated . Thanks
Tanvir Ahamed
Göteborg, Sweden | mashranga at yahoo.com
More information about the R-help
mailing list