[英]How to extract the dates of a column considering other column condition in a dataframe in r?
I have a big dataset with 1200 rows, which looks like this:我有一个包含 1200 行的大数据集,如下所示:
Date![]() |
CAL_CALFIXO ![]() |
FIXOCAL![]() |
---|---|---|
2015-07-20 ![]() |
Yes![]() |
No![]() |
2015-07-21 ![]() |
Yes![]() |
No![]() |
2015-07-22 ![]() |
No![]() |
No![]() |
2015-07-23 ![]() |
No![]() |
Yes![]() |
2015-07-24 ![]() |
No![]() |
No![]() |
2015-07-25 ![]() |
Yes![]() |
Yes![]() |
2015-07-26 ![]() |
No![]() |
No![]() |
.......... ![]() |
........... ![]() |
....... ![]() |
The Date is in Date format.日期为日期格式。
My question is the following: how to extract the dates where CAL_CALFIXO and FIXOCAL are "Yes"?我的问题如下:如何提取 CAL_CALFIXO 和 FIXOCAL 为“是”的日期? The code can have both columns CAL_CALFIXO and FIXOCAL together or separate.
代码可以将 CAL_CALFIXO 和 FIXOCAL 列放在一起或分开。
My desired output would look like this (where at least one variable is "Yes"):我想要的 output 看起来像这样(其中至少一个变量是“是”):
Date![]() |
CAL_CALFIXO ![]() |
FIXOCAL![]() |
---|---|---|
2015-07-20 ![]() |
Yes![]() |
No![]() |
2015-07-21 ![]() |
Yes![]() |
No![]() |
2015-07-23 ![]() |
No![]() |
Yes![]() |
2015-07-24 ![]() |
No![]() |
Yes![]() |
2015-07-25 ![]() |
Yes![]() |
Yes![]() |
.......... ![]() |
........... ![]() |
....... ![]() |
Any help will be much appreciated.任何帮助都感激不尽。
When you post an image with your data is a little difficult understand the structure of your data.当您发布带有数据的图像时,有点难以理解数据的结构。 You can review this link https://stackoverflow.com/help/how-to-ask .
您可以查看此链接https://stackoverflow.com/help/how-to-ask 。
Using your data and the library tidyverse I believe that I have your answer.使用你的数据和图书馆 tidyverse 我相信我有你的答案。
library(tidyverse)
df<-data.frame(Date=seq(as.Date("2015-07-20"), as.Date("2015-07-26"), by="day"),
CAL_CALFIXO=c("yes","yes","no", "no", "no","yes", "no" ),
FIXOCAL=c("no","no","no","yes","no","yes","no")) # The DF with your data
Date<-df%>%filter(., CAL_CALFIXO=="yes"&FIXOCAL=="yes")%>% #Filter extract the columns with the desired characteristics
select(., Date)# with Select I am choosing to save only the Column Date in a new Dataframe.
My output is:我的 output 是:
>Date
Date
1 2015-07-25
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.