Dear Users of R, I have a data frame with three column, the first column contains years, the second one months and third one, the days (cbind(yyyy mm dd)). I want to combine them so that i have one column with the date format as (dd.mm.yyyy). Is there a way of doing that. Thanks in advance, Eliza [[alternative HTML version deleted]]
eliza botto <eliza_botto <at> hotmail.com> writes:> > Dear Users of R, > I have a data frame with three column, the first column contains years,the second one months and third one,> the days (cbind(yyyy mm dd)). I want to combine them so that i have onecolumn with the date format as (dd.mm.yyyy).> Is there a way of doing that. > Thanks in advance, > ElizaI think just paste(dd,mm,yyyy,sep=".") should work fine (where 'dd','mm', 'yyyy' are references to your columns)
Hi, Try: dat1 <- data.frame(years=rep(1991:1992,12), months=rep(1:12,2),days= rep(1,24)) ?dat1$day <- format(as.Date(paste(dat1[,1],sprintf("%02d",dat1[,2]),sprintf("%02d",dat1[,3]),sep="."),"%Y.%m.%d"),"%d.%m.%Y") A.K. On Thursday, November 28, 2013 8:56 AM, eliza botto <eliza_botto at hotmail.com> wrote: Dear Users of R, I have a data frame with three column, the first column contains years, the second one months and third one, the days (cbind(yyyy mm dd)). I want to combine them so that i have one column with the date format as (dd.mm.yyyy). Is there a way of doing that. Thanks in advance, Eliza ??? ??? ??? ? ??? ??? ? ??? [[alternative HTML version deleted]] ______________________________________________ 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.
Dear bert, arun and philipps,Thanks for your help. It worked perfectly fine for me.:D Eliza> Date: Thu, 28 Nov 2013 16:09:58 +0100 > From: wevphi@web.de > To: eliza_botto@hotmail.com; r-help@r-project.org > Subject: Re: [R] date format > > Hi Eliza, > > # you can use paste to create a new vector: > date1<-paste( dataframe[,3], dataframe[,2],dataframe[,1], sep="." ) > > # you could then turn that into a Date-Time-Class with which you could > do calculations > strptime(date1, format="%d.%m.%Y") > > > Am 28.11.2013 14:54, schrieb eliza botto: > > Dear Users of R, > > I have a data frame with three column, the first column contains years, the second one months and third one, the days (cbind(yyyy mm dd)). I want to combine them so that i have one column with the date format as (dd.mm.yyyy). > > Is there a way of doing that. > > Thanks in advance, > > Eliza > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > 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. > > > -- > -------------------- > Philipp Wevers > wevphi@web.de > Mobil: 015253710061 > fest: 03080921097 > Koloniestraße 126 A > 13359 Berlin > wevphi@web.de > > > --- > Diese E-Mail ist frei von Viren und Malware, denn der avast! Antivirus Schutz ist aktiv. > http://www.avast.com >[[alternative HTML version deleted]]
Hello, Maybe something like the following. dat <- data.frame(yyyy = 2011:2013, mm = 1:3, dd = 4:6) apply(dat, 1, function(x) paste(rev(x), collapse = ".")) Hope this helps, Rui Barradas Em 28-11-2013 13:54, eliza botto escreveu:> Dear Users of R, > I have a data frame with three column, the first column contains years, the second one months and third one, the days (cbind(yyyy mm dd)). I want to combine them so that i have one column with the date format as (dd.mm.yyyy). > Is there a way of doing that. > Thanks in advance, > Eliza > [[alternative HTML version deleted]] > > ______________________________________________ > 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. >