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.
在R中,na.omit()函数可用于丢弃包含NA值的data.frame中的条目。作为副作用,如果确实丢弃了行,则该函数向结果添加属性“省略”,该结果包含被丢弃的row.names的向量。
I want to discard this 'omit' attribute because I don't need it. What is the best way to do that?
我想丢弃这个'省略'属性,因为我不需要它。最好的方法是什么?
1 个解决方案
#1
12
Just use data.frame
after na.omit
or you can do it directly:
只需在na.omit之后使用data.frame,或者直接执行:
> 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
#1
12
Just use data.frame
after na.omit
or you can do it directly:
只需在na.omit之后使用data.frame,或者直接执行:
> 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