[R] How to delete matrix rows based on NA frequency?

2010-01-15 Thread Joel Fürstenberg-Hägg
Hi all, I would like to remove rows from a matrix, based on the frequency of missing values. If there are more than 10 % missing values, the row should be deleted. I use the following to calculate the frequencies, thereby getting a new matrix with the frequencies:

Re: [R] How to delete matrix rows based on NA frequency?

2010-01-15 Thread Remko Duursma
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

Re: [R] How to delete matrix rows based on NA frequency?

2010-01-15 Thread Henrique Dallazuanna
Try this: m[prop.table(rowSums(is.na(m))) 0.1,] 2010/1/15 Joel Fürstenberg-Hägg joel_furstenberg_h...@hotmail.com: Hi all, I would like to remove rows from a matrix, based on the frequency of missing values. If there are more than 10 % missing values, the row should be deleted. I