简体   繁体   中英

Selecting a subset of rows that meet a TRUE condition

I have a dataframe df . I want to plot two variables, a and t , against each other, but using only certain rows. The rows I want to use must meet three conditions:

  1. A third variable, s , must be >= 0.9
  2. The third variable s must also be <=1.1
  3. I only want the rows that have met the condition of having no NAs/missing values for a , t , and s .

I have created a logical vector that returns values of TRUE and FALSE to meet this third condition, but I don't know how to work this into my code.

Here is my code so far, which I believe produces the desired result with the exception of the third condition:

plot(log(df$t)[df$s >= .9 & df$s <= 1.1],log(df$a)[df$s >= .9 & df$s <= 1.1]) 

What can I add to it to satisfy the third condition?

library(ggplot2)
p <- ggplot(data=df[df$s >= 0.9 & df$s <= 1.1 & !is.na(df$a) & !is.na(df$s) & !is.na(df$t),])
p + geom_point(aes(x = t, y = a))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM