如何識別和刪除列表中空的條目,但不是NA或NULL。爲什麼當我嘗試比較它的元素時,我的列表似乎是一個因素?刪除清單中的空條目
> s <- subset(world, (oil == "Yes") & !is.na(effectiveness) & !is.null(effectiveness), select = effectiveness)
> s
effectiveness
3 32.62411409517834
30 31.91489350429382
41
54 23.8770690651932
64 35.93380642839076
80 33.3333332769696
81 35.6973993299137
116 50.118203450602
131 20.09456253502668
181
194 19.62174974716583
> typeof(s)
[1] "list"
> sum(s)
Error in FUN(X[[1L]], ...) :
only defined on a data frame with all numeric variables
> s[s > 0]
[1] NA NA NA NA NA NA NA NA NA NA NA
Warning message:
In Ops.factor(left, right) : > not meaningful for factors
看起來像你可能有一個空間或一束空間,讓你的列「effectivenes」是一種因子(當你裝好了)。嘗試搜索並用「」替換空格「」 – infominer
's'是一個data.frame。 'typeof'返回底層存儲類型,而不是類。很難知道爲什麼''效率'是一個因素,而不知道你是如何創建's''的。 –
@JoshuaUlrich'world'是一個數據框。你可以看到我在上面的第一行創建了's'。 –