[R] How do I access a specific element of a multi-dimensional list
JS Huang
js.huang at protective.com
Fri Feb 20 22:52:40 CET 2015
Hi,
Jim's answer is neat. There is an issue on the result. All are
characters even though some are numeric or logic. The following
implementation retains the variable type.
> x
[[1]]
[1] 2 3 5
[[2]]
[1] "aa" "bb" "cc"
[[3]]
[1] TRUE FALSE TRUE
> getFirst
function(aList)
{
result <- list()
for (i in 1:length(aList))
{
result <- c(result, aList[[i]][1])
}
return(result)
}
> getFirst(x)
[[1]]
[1] 2
[[2]]
[1] "aa"
[[3]]
[1] TRUE
>
--
View this message in context: http://r.789695.n4.nabble.com/How-do-I-access-a-specific-element-of-a-multi-dimensional-list-tp4703596p4703622.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list