Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discarding a single attribute in R

Tags:

r

missing-data

In R, the na.omit() function can be used to discard entries in a data.frame that contain NA values. As a side effect, if lines are indeed discarded, the function adds an attribute 'omit' to the result that contains a vector of the row.names that were discarded.

I want to discard this 'omit' attribute because I don't need it. What is the best way to do that?

like image 723
reddish Avatar asked Dec 07 '11 04:12

reddish


1 Answers

Just use data.frame after na.omit or you can do it directly:

> temp <- data.frame(a=c(1,NA,44),b=c(99,29,NA))
> new <- na.omit(temp)
> attributes(new)
$names
[1] "a" "b"

$row.names
[1] 1

$class
[1] "data.frame"

$na.action
2 3
2 3
attr(,"class")
[1] "omit"

> reduced <- data.frame(new)
> attributes(reduced)
$names
[1] "a" "b"

$row.names
[1] 1

$class
[1] "data.frame"
>

direct method:

attributes(new)$na.action <- NULL
like image 116
Xu Wang Avatar answered Oct 13 '22 21:10

Xu Wang