Message at the end of na.omit

2

I am using the command na.omit(matrix.work) and at the end the message appears:

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

Someone knows how I can delete this message because I do not want it to appear because it is loading the contents into a variable.

    
asked by anonymous 06.09.2016 / 05:11

1 answer

2

This message is not a problem ... These are just attributes that the function places on the resulting array. An array with these attributes will continue to behave as 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 to the attribute that the na.omit function added, which is equivalent to deleting it.

A more concise but less intuitive way is to do:

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

This results in an array without extra attributes by a characteristic of the [ function, which can be found in the document ( ?"[" ):

  

Subsetting (except for an empty index) will drop all attributes except   names, dim and dimnames.

    
06.09.2016 / 12:44