Skip to content

How to delete matrix rows based on NA frequency?

3 messages · Joel Fürstenberg-Hägg, Remko Duursma, Henrique Dallazuanna

#
Joel,

try this:

# sample matrix
m <- matrix(sample(c(1:10, NA),150,replace=T),byrow=T,ncol=15)

# nr of missing values per row
nacounts <- apply(m, 1, function(x)length(x[is.na(x)]))

# new matrix
newm <- m[nacounts/ncol(m) < 0.1,]




greetings,
Remko


-------------------------------------------------
Remko Duursma
Post-Doctoral Fellow

Centre for Plants and the Environment
University of Western Sydney
Hawkesbury Campus
Richmond NSW 2753

Dept of Biological Science
Macquarie University
North Ryde NSW 2109
Australia

Mobile: +61 (0)422 096908
www.remkoduursma.com



2010/1/15 Joel F?rstenberg-H?gg <joel_furstenberg_hagg at hotmail.com>:
#
Try this:

m[prop.table(rowSums(is.na(m))) < 0.1,]

2010/1/15 Joel F?rstenberg-H?gg <joel_furstenberg_hagg at hotmail.com>: