jinni jinni - 1 year ago 65
R Question

How to plot a subset of a data frame in R?

Is there a simple way to do this in 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

Answer Source

with(dfr[dfr$var3 < 155,], plot(var1, var2)) should do the trick.

Edit regarding multiple conditions:

with(dfr[(dfr$var3 < 155) & (dfr$var4 > 27),], plot(var1, var2))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download