Hello. I have a problem with 2 dataframes. There are 2 columns - "value" and "dates". These dataframes have different dimension. Some dates coincide. And I need to intersect them by dates and have on output two dataframes with identical columns "dates" and new dimension . "value" have to recieve in compliance with dates. Regards, Aleksander. [[alternative HTML version deleted]]
That sounds like a job for merge(), but it's hard to be sure because you didn't provide the information requested in the posting guide. Sarah On Tue, Jun 26, 2012 at 11:03 AM, ??????????? ????????? <vasilchenko.a.p at gmail.com> wrote:> Hello. > I have a problem with 2 dataframes. There are 2 columns - "value" and > "dates". These dataframes have different dimension. Some dates coincide. > And I need to intersect them by dates and have on output two dataframes > with identical columns "dates" and new dimension . "value" have to > recieve in compliance with dates. > Regards, Aleksander. >-- Sarah Goslee http://www.functionaldiversity.org
Hi. Try with following functions: ?intersection ?"%in%" ?"[" Perhaps someone will provide you more help if you read and follow posting guide http://www.R-project.org/posting-guide.html<http://www.r-project.org/posting-guide.html> Andrija On Tue, Jun 26, 2012 at 5:03 PM, ÷ÁÓÉÌØÞÅÎËÏ áÌÅËÓÁÎÄÒ < vasilchenko.a.p@gmail.com> wrote:> Hello. > I have a problem with 2 dataframes. There are 2 columns - "value" and > "dates". These dataframes have different dimension. Some dates coincide. > And I need to intersect them by dates and have on output two dataframes > with identical columns "dates" and new dimension . "value" have to > recieve in compliance with dates. > Regards, Aleksander. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org 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. >[[alternative HTML version deleted]]
Hi,
Try this:
?dat1<-data.frame(value=c(15,20,25,30,45,50),dates=c("2005-05-25","2005-06-25","2005-07-25","2005-08-25","2005-09-25","2005-10-25"))
dat2<-data.frame(value=c(15,20,25,50),dates=c("2005-05-25","2005-06-25","2005-07-25","2005-10-25"))
?merge(dat1,dat2, by="dates")
?????? dates value.x value.y
1 2005-05-25????? 15????? 15
2 2005-06-25????? 20????? 20
3 2005-07-25????? 25????? 25
4 2005-10-25????? 50????? 50
or
subset(dat1,(dates %in% dat2$dates))
? value????? dates
1??? 15 2005-05-25
2??? 20 2005-06-25
3??? 25 2005-07-25
6??? 50 2005-10-25
I hope this is what you meant.? You mentioned the datasets have different
dimensions.? Not sure what you meant.
A.K.
----- Original Message -----
From: ??????????? ????????? <vasilchenko.a.p at gmail.com>
To: r-help at r-project.org
Cc:
Sent: Tuesday, June 26, 2012 11:03 AM
Subject: [R] Intersection
Hello.
I have a problem with 2 dataframes. There are 2 columns - "value" and
"dates". These dataframes have different dimension. Some dates
coincide.
And I need to intersect them by dates and have on output two dataframes
with identical columns "dates" and new dimension . "value"
have to
recieve in compliance with dates.
Regards, Aleksander.
??? [[alternative HTML version deleted]]
______________________________________________
R-help at r-project.org 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.