[英]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. 我想相对绘制两个变量
a
和t
,但只使用某些行。 The rows I want to use must meet three conditions: 我要使用的行必须满足三个条件:
s
, must be >= 0.9 s
必须> = 0.9 s
must also be <=1.1 s
也必须<= 1.1 a
, t
, and s
. a
, t
和s
没有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. 我创建了一个逻辑向量,该向量返回
TRUE
和FALSE
值以满足第三个条件,但是我不知道如何将其用于代码中。
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.