0

I have two separate dataframe, one (frame1) has the general info about the location of sensors and the other one (frame2) has the time series for all the locations with the siteIDs column common between the two.

I want to add another column to frame2. I thought it would be possible to use lapply, but it is not working. I have also tried using [[ instead of $, no gain. It does not produce any warning or error. It simply does not do anything.

gaugeList<-as.list(unique(frame2$siteIDs))
frame2[['timeZone']]<-as.character(NA)
lapply(gaugeList,function(gaugeX) { frame2$timeZone[which(frame2$siteIDs==gaugeX)] <- (as.character(frame1$timeZone[which (frame1$siteIDs==gaugeX)]))})
newbie
  • 757
  • 1
  • 9
  • 19
  • can you dput the head of both of your data frames for a reproducible example? I am also guessing you need to be more specific in your function - gaugeX will be passing through the whole row. – jeremycg Jul 14 '15 at 22:45
  • Thanks, my problem got solved. TZ<-frame1$timeZone names(TZ)<-(farme1$siteIDs) frame2$timeZone<-TZ[as.character(rame2$siteIDs)] – newbie Jul 14 '15 at 23:19
  • You are welcome to answer your own question and accept it. – mathematical.coffee Jul 14 '15 at 23:29

0 Answers0