filter one entry, in dependence of date

classic Classic list List threaded Threaded
2 messages Options
Mat
Reply | Threaded
Open this post in threaded view
|

filter one entry, in dependence of date

Mat
This post has NOT been accepted by the mailing list yet.
hello together, i have a short question, maybe you can help me.

I have a data.frame like this one
     ID    Month       Value
1    1     03-2014        1
2    1     04-2014        10
3    1     05-2014        50
4    2     03-2014         8
5    2     04-2014         7
6    2     05-2014         4
7    2     06-2014         2

I now want to create another data.frame without the lines from ID==2 which are earlier than 05-2014

The solution look like this one:

     ID    Month       Value
1    1     03-2014        1
2    1     04-2014        10
3    1     05-2014        50
4    2     05-2014         4
5    2     06-2014         2

maybe you can help me.

Best regards. Mat
Reply | Threaded
Open this post in threaded view
|

Re: filter one entry, in dependence of date

arun kirshna
Hi,
If `dat` is the dataset:
dat[!(dat$ID==2 & as.numeric(gsub("-.*","",dat$Month))<5),]
  ID   Month Value
1  1 03-2014     1
2  1 04-2014    10
3  1 05-2014    50
6  2 05-2014     4
7  2 06-2014     2

A.K.



hello together, i have a short question, maybe you can help me.

I have a data.frame like this one
     ID    Month       Value
1    1     03-2014        1
2    1     04-2014        10
3    1     05-2014        50
4    2     03-2014         8
5    2     04-2014         7
6    2     05-2014         4
7    2     06-2014         2

I now want to create another data.frame without the lines from ID==2 which are earlier than 05-2014

The solution look like this one:

     ID    Month       Value
1    1     03-2014        1
2    1     04-2014        10
3    1     05-2014        50
4    2     05-2014         4
5    2     06-2014         2

maybe you can help me.

Best regards. Mat


______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.