Skip to content
Prev 295148 / 398506 Next

Prevent calculation when only NA

Try this.

check.na <- function(mat){
	nas <- NULL
	for(st in seq.int(ncol(mat)))
		if(sum(is.na(mat[, st])) == nrow(mat) - 1) nas <- c(nas, st)
	if(length(nas)){
		mat <- mat[, -nas]
		mat <- mat[-nas, ]
	}
	mat
}
	
check.na(df1)
      file1 file3
file1   1.0   0.8
file3   0.8   1.0

Note that you must remove both the columns and the rows, it's a correlation
matrix.
And that's also why the 'ncol(mat) minus 1', the diagonal value need not be
NA.

Rui Barradas

jeff6868 wrote
--
View this message in context: http://r.789695.n4.nabble.com/Prevent-calculation-when-only-NA-tp4630716p4630732.html
Sent from the R help mailing list archive at Nabble.com.