How to get values from a list?

Viewed 11706

I have a list with uniform size as below. I want to extract the values for the keys. How do I do it?

I have isolated the keys by using names(allsum) where allsum looks like this

`$1999
[1] 7332967

$2002
[1] 5635780

$2005
[1] 5454703

$2008
[1] 3464206`

I want [7332967, 5635780, 5454703, 3464206] as the output. I tried sapply but have a weak intuition. Please help.

for(a in allsum) {
  print(a[[1]])
}

I tried this, it works, but I want to know if we can do it with some function or without any explicit looping.

I tried using unlist Following is what happens

c1 <- unlist(allsum) 
 #1999    2002    2005    2008 
#7332967 5635780 5454703 3464206

I just need the big numbers. How do I extract?

4 Answers
Related