[R] add a data frame to my data frame

arun smartpink111 at yahoo.com
Tue Sep 25 18:10:15 CEST 2012


HI,
I guess this is what you are looking for:
merge(myframe2,environ2, by="ID")
#     ID Hunger        myframestime Temp Rain          envirotime
#1  Bert      2 2012-09-24 10:00:00   27    2 2012-09-25 10:00:00
#2  Bert      2 2012-09-25 10:00:00   27    2 2012-09-25 10:00:00
#3 Ernie      1 2012-09-24 09:00:00   25  0.1 2012-09-24 09:00:00
#4 Ernie      1 2012-09-24 09:00:00   30    5 2012-09-25 09:00:00
#5 Ernie      1 2012-09-25 09:00:00   25  0.1 2012-09-24 09:00:00
#6 Ernie      1 2012-09-25 09:00:00   30    5 2012-09-25 09:00:00
A.K.




----- Original Message -----
From: Tagmarie <Ramgad82 at gmx.net>
To: r-help at r-project.org
Cc: 
Sent: Tuesday, September 25, 2012 10:44 AM
Subject: [R] add a data frame to my data frame

Hello, 
Once again I feel so dumb. Can anyone help me? 
I have a data frame somewhat like that: 

myframe <- data.frame (ID=c("Ernie", "Ernie", "Bert", "Bert"),
Timestamp=c("24.09.2012 09:00", "25.09.2012 09:00", "24.09.2012 10:00",
"25.09.2012 10:00"), Hunger=c("1","1","2","2") )
myframestime <- as.POSIXct (strptime(as.character(myframe$Timestamp),
"%d.%m.%Y %H:%M"), tz="GMT")
myframe2 <- cbind (myframe,myframestime)
myframe2$Timestamp <- NULL 

Now I have a second dataframe with environmental variables. Something like
this: 

environ <- data.frame (ID=c("Ernie", "Ernie", "Bert"),
Timestamp=c("24.09.2012 09:00", "25.09.2012 09:00", "25.09.2012 10:00"),
Temp=c("25","30","27"), Rain =c ("0.1", "5", "2"))
envirotime <- as.POSIXct (strptime(as.character(environ$Timestamp),
"%d.%m.%Y %H:%M"), tz="GMT")
environ2 <- cbind (environ,envirotime)
environ2$Timestamp <- NULL

How do I merge or handle the two data frames at the respective lines so that
I get the data (Temp, Rain) at the correct line with (Hunger)? 






--
View this message in context: http://r.789695.n4.nabble.com/add-a-data-frame-to-my-data-frame-tp4644122.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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.





More information about the R-help mailing list