简体   繁体   English

选择满足TRUE条件的行的子集

[英]Selecting a subset of rows that meet a TRUE condition

I have a dataframe df . 我有一个数据框df I want to plot two variables, a and t , against each other, but using only certain rows. 我想相对绘制两个变量at ,但只使用某些行。 The rows I want to use must meet three conditions: 我要使用的行必须满足三个条件:

  1. A third variable, s , must be >= 0.9 第三个变量s必须> = 0.9
  2. The third variable s must also be <=1.1 第三个变量s也必须<= 1.1
  3. I only want the rows that have met the condition of having no NAs/missing values for a , t , and s . 我只希望满足ats没有NAs /缺失值的条件的行。

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. 我创建了一个逻辑向量,该向量返回TRUEFALSE值以满足第三个条件,但是我不知道如何将其用于代码中。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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