[英]How to plot a subset of a data frame in R?
Is there a simple way to do this in R: 在R中有一个简单的方法吗?
plot(var1,var2, for all observations in the data frame where var3 < 155)
It is possible by creating a new data newdata <- data[which( data$var3 < 155),]
but then I have to redefine all the variables newvar1 <- newdata$var1
etc. 可以通过创建新数据newdata <- data[which( data$var3 < 155),]
然后我必须重新定义所有变量newvar1 <- newdata$var1
等。
with(dfr[dfr$var3 < 155,], plot(var1, var2))
should do the trick. with(dfr[dfr$var3 < 155,], plot(var1, var2))
应该可以解决问题。
Edit regarding multiple conditions: 编辑多个条件:
with(dfr[(dfr$var3 < 155) & (dfr$var4 > 27),], plot(var1, var2))
Most straightforward option: 最简单的选择:
plot(var1[var3<155],var2[var3<155])
It does not look good because of code redundancy, but is ok for fast n
dirty hacking. 它看起来并不好,因为代码的冗余,但确定快速n
肮脏的黑客。
This is how I would do it, in order to get in the var4 restriction: 这就是我要做的,为了获得var4限制:
dfr<-data.frame(var1=rnorm(100), var2=rnorm(100), var3=rnorm(100, 160, 10), var4=rnorm(100, 27, 6))
plot( subset( dfr, var3 < 155 & var4 > 27, select = c( var1, var2 ) ) )
Rgds, Rainer Rgds,Rainer
This chunk should do the work: 这个块应该做的工作:
plot(var2 ~ var1, data=subset(dataframe, var3 < 150))
My best regards. 我最诚挚的问候。
How this works: 这是如何工作的:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.