Mangalani Peter Makananisa
2014-Jun-26 10:42 UTC
[R] Combining character, numeric and dates fields in one data frame
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 Please Note: This email and its contents are subject to our email legal notice which can be viewed at http://www.sars.gov.za/AllDocs/Documents/email_disclaimer.pdf [[alternative HTML version deleted]]
Jim Lemon
2014-Jun-26 22:41 UTC
[R] Combining character, numeric and dates fields in one data frame
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 onthe> same data after using the as.Date & as.yearmon and be able tomanipulate> 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