【发布时间】:2018-11-08 02:24:34
【问题描述】:
我有与我的主题相关的新问题 deleting outlier in r with account of nominal var。 在新情况下,变量 x 和 x1 具有不同的长度
x <- c(-10, 1:6, 50)
x1<- c(-20, 1:5, 60)
z<- c(1,2,3,4,5,6,7,8)
bx <- boxplot(x)
bx$out
bx1 <- boxplot(x1)
bx1$out
x<- x[!(x %in% bx$out)]
x1 <- x1[!(x1 %in% bx1$out)]
x_to_remove<-which(x %in% bx$out)
x <- x[!(x %in% bx$out)]
x1_to_remove<-which(x1 %in% bx1$out)
x1 <- x1[!(x1 %in% bx1$out)]
z<-z[-unique(c(x_to_remove,x1_to_remove))]
z
data.frame(cbind(x,x1,z))
然后我收到警告
Warning message:
In cbind(x, x1, z) :
number of rows of result is not a multiple of vector length (arg 2)
所以在新的数据框中,obs。 Z 不对应于 x 和 x1。 我该如何决定这个问题? 这个解决方案对我没有帮助 Rsolnp: In cbind(temp, funv) : number of rows of result is not a multiple of vector length (arg 1) 或者我只是做错了什么。
编辑
x_to_remove<-which(x %in% bx$out)
x <- x[!(x %in% bx$out)]
x1_to_remove<-which(x1 %in% bx1$out)
x1 <- x1[!(x1 %in% bx1$out)]
z<-z[-unique(c(x_to_remove,x1_to_remove))]
z
d=data.frame(cbind(x,x1,z))
d
错了 警告信息:
In cbind(x, x1, z) :
number of rows of result is not a multiple of vector length (arg 2)
d
x x1 z
1 1 1 2
2 2 2 3
3 3 3 4
4 4 4 5
5 5 5 6
6 6 1 2
这 3 列如何得到这个输出
Na Na Na
1 1 2
2 2 3
3 3 4
4 4 5
5 5 6
Na Na Na
Na Na Na
六排(d)是多余的
【问题讨论】:
-
好吧,你不能列绑定3个不同长度的向量,我不明白你的目标是什么。
标签: r dataframe dplyr mean outliers