Message at the end of na.omit

Asked

Viewed 84 times

2

I’m using the remote na.omit(matrix.work) and the message appears at the end:

attr(,"na.action")
[1]  3 11
attr(,"class"

Does anyone know how to delete this message, because I don’t want it to appear because it is loading the content into a variable.

1 answer

2

This message is not a problem... It is only attributes that the function puts in the resulting matrix. An array with these attributes will continue to behave like an array. Just ignore them.

That said, if you still want to delete it, you can do the following:

a <- matrix(rep(c(NA, 1:4), each = 20), ncol = 10, byrow = T)
b <- na.omit(a)
attr(b, "na.action") <- NULL
b
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
[1,]    1    1    1    1    1    1    1    1    1     1
[2,]    1    1    1    1    1    1    1    1    1     1
[3,]    2    2    2    2    2    2    2    2    2     2
[4,]    2    2    2    2    2    2    2    2    2     2
[5,]    3    3    3    3    3    3    3    3    3     3
[6,]    3    3    3    3    3    3    3    3    3     3
[7,]    4    4    4    4    4    4    4    4    4     4
[8,]    4    4    4    4    4    4    4    4    4     4

In the line that has attr(b, "na.action") <- NULL you are assigning NULL the attribute that the function na.omit added, which is equivalent to excluding it.

A more concise but less intuitive way is to do:

b <- na.omit(a)[T,T]

This results in a matrix with no extra attributes by a function feature [, which can be found in the document (?"["):

Subsetting (except by an Empty index) will drop all Attributes except Names, dim and dimnames.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.