On Thu, 26 Jun 2014 10:42:54 AM Mangalani Peter Makananisa wrote: > Hi, > > I am try to fix the data frame and I see that we only have two fields > defined characters and numeric fields. How do I add date field on the > same data after using the as.Date & as.yearmon and be able to manipulate > the data on the date field(s)? > > Please advise > > > Kind regards > > peter > Hi peter, Let's say the two fields in your data frame are:
mydata$date<-c("2014-06-01","2014-06-02",...,"2014-06-30") mydata$mintemp<-c(14,17,...,12) If you want to change the character dates to date objects: mydata$date<-as.Date(mydata$date,"%Y-%m-%d") If your data frame doesn't contain the dates already: mydata$weather<-c("clear","cloudy",...,"rain") mydata$mintemp<-c(14,17,...,12) and you have a vector of the dates as character fields: mydates<-c("2014-06-01","2014-06-02",...,"2014-06-30") mydata$date<-as.Date(mydates,"%Y-%m-%d") Jim ______________________________________________ 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.