0

I have a biglistthat contains 0 sublists, each of which are List of 1.

When I do >biglist I get this:

            [,1]       [,2]       [,3]       [,4]       [,5]       [,6]       [,7]       [,8]   
LIST1       Numeric,6  Numeric,6  Numeric,6  Numeric,6  Numeric,6  Numeric,6  Numeric,6  Numeric,6  

Each sub-list contains both integer values and NA values. i.e.

>biglist[1] yields

NA 0.50 NA NA 0.25 1.00 NA 0.00`

>biglist[2] yields

0.500 0.375 0.000 0.500 NA 0.500 0.500 NA

And so on. I'm trying to find the 50th percentile and 95th percentile of all of the integer values of the sublists, but I want to get rid of the NA values. How would I accomplish this?

EDIT: Reproducible example biglist <- list(c(NA, 0.5, NA, NA, 0.25, 1, NA, 0), c(0.5, NA, NA, NA, NA,NA, NA, NA), c(0.5, 0.375, 0, 0.5, NA, 0.5, 0.5, NA), c(NA, NA,NA, NA, NA, 0.5, 0.5, 0.333333333333333), c(NA, NA, 0.125, NA,0.5, 1, 0.5, 0.5), c(0.5, 0.25, 0.5, NA, NA, NA, NA, 0.5), c(0.625,NA, NA, 0.5, NA, NA, NA, NA), c(0.25, NA, 0.5, NA, NA, NA, NA,0.333333333333333), c(0.25, 0.75, NA, 0.5, 0.5, NA, 0, NA), c(NA,NA, 0.375, NA, 0.5, 0.5, 1, NA))

Brian Lee
  • 39
  • 7
  • Hello and welcome to SO. To help make a reproducible example, you can use `reproduce()` . Instructions are here: http://bit.ly/SORepro - [How to make a great R reproducible example](http://bit.ly/SORepro) – Ricardo Saporta Sep 27 '14 at 18:33

1 Answers1

1

use lapply or sapply as follows

sapply(biglist, quantile, prob=c(.50, .95), na.rm=TRUE )
#      [,1] [,2] [,3] [,4] [,5] [,6]    [,7]     [,8] [,9] [,10]
# 50% 0.375  0.5  0.5  0.5  0.5  0.5 0.56250 0.333333  0.5 0.500
# 95% 0.925  0.5  0.5  0.5  0.9  0.5 0.61875 0.483333  0.7 0.925

sapply(biglist, quantile, prob=c(.50, .95), na.rm=TRUE, simplify=FALSE )
# [[1]]
#   50%   95% 
# 0.375 0.925 

# [[2]]
# 50% 95% 
# 0.5 0.5 

# [[3]]
# 50% 95% 
# 0.5 0.5 

# [[4]]
# 50% 95% 
# 0.5 0.5 

# [[5]]
# 50% 95% 
# 0.5 0.9 

# [[6]]
# 50% 95% 
# 0.5 0.5 

# [[7]]
#     50%     95% 
# 0.56250 0.61875 

# [[8]]
#      50%      95% 
# 0.333333 0.483333 

# [[9]]
# 50% 95% 
# 0.5 0.7 

# [[10]]
#   50%   95% 
# 0.500 0.925 
Ricardo Saporta
  • 54,400
  • 17
  • 144
  • 178