You still seem to be having problems, so where is the promised reproducible example?
Dan Daniel Nordlund, PhD Research and Data Analysis Division Services & Enterprise Support Administration Washington State Department of Social and Health Services > -----Original Message----- > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Shivi > Bhatia > Sent: Tuesday, July 26, 2016 4:43 AM > To: Duncan Murdoch > Cc: r-help@r-project.org > Subject: Re: [R] Date Time in R > > Thanks Duncan for the quick response. I will check again as you suggested. > If that doesn't work i will share a reproducible example. > > Thanks again!!!! > > On Tue, Jul 26, 2016 at 4:43 PM, Duncan Murdoch > <murdoch.dun...@gmail.com> > wrote: > > > On 26/07/2016 7:05 AM, Shivi Bhatia wrote: > > > >> Hi Team, > >> > >> This scenario may have come across a number of times however i > >> checked nabble & SO and couldn't find a solution hence request > assistance. > >> > >> I have a date variable in my data-set eir. The class of this var was > >> character while i had read the file in r studio. Example of date - > >> 05-30-16 > >> > >> To change this i have used eir$date<- as.Date(eir$date, "%m-%d-%y"). > >> This converts it to a date variable. However when i check few obs > >> with head(eir$date) all the results are <NA>. > >> > > > > I think you don't have character data like that, because I see > > > > > as.Date("05-30-16", "%m-%d-%y") > > [1] "2016-05-30" > > > > I'd guess eir$date is really a factor, because character data is > > frequently changed to factor automatically. If that's the case, this > > should work for the conversion: > > > > as.Date(as.character(eir$date), "%m-%d-%y") > > > > If that doesn't work, you'll need to post something reproducible. > > > > Duncan Murdoch > > > > I also need to create weekdays from this date variable but until i get > > this > >> resolved i cant find a weekday. For weekday i have used: > >> eir$week<- (eir$date) > >> eir$week<- weekdays(as.Date(eir$week)) > >> class(eir$week) > >> eir$week<- as.factor(eir$week) > >> head(eir$week) > >> > >> Head of this eir$week results again as expected in <NA> but shows > Levels: > >> Friday Monday Saturday Sunday Thursday Tuesday Wednesday > >> > >> Not sure what i should do here. Kindly suggest. > >> > >> [[alternative HTML version deleted]] > >> > >> ______________________________________________ > >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > >> 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]] > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.