我在R中看到了一些数据.一个标题为"Height"的特定列包含几行NA.
我期待我的数据框的子集,以便从我的分析中排除高于某个值的所有高度.
df2 <- subset ( df1 , Height < 40 )
Run Code Online (Sandbox Code Playgroud)
但是,每当我执行此操作时,R会自动删除包含高度NA值的所有行.我不想要这个.我试过为na.rm包含参数
f1 <- function ( x , na.rm = FALSE ) {
df2 <- subset ( x , Height < 40 )
}
f1 ( df1 , na.rm = FALSE )
Run Code Online (Sandbox Code Playgroud)
但这似乎没有做任何事情; NA的行仍然从我的数据框中消失.有没有一种方法可以对我的数据进行子集化,而不会丢失NA行?