jinni jinni - 4 months ago 12
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


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))