Dear R forum I have a data.frame df = data.frame(dates = c("4/15/2013", "4/14/2013", "4/13/2013", "4/12/2013"), values = c(47, 38, 56, 92)) I need to to create a vector by repeating the dates as "Current_date", 4/15/2013, 4/14/2013, 4/13/2013, 4/12/2013, "Current_date", 4/15/2013, 4/14/2013, 4/13/2013, 4/12/2013, Current_date, 4/15/2013, 4/14/2013, 4/13/2013, 4/12/2013 i.e. I need to create a new vector as given below which I need to use for some other purpose. Current_date 4/15/2013 4/14/2013 4/13/2013 4/12/2013 Current_date 4/15/2013 4/14/2013 4/13/2013 4/12/2013 Current_date 4/15/2013 4/14/2013 4/13/2013 4/12/2013 Is it possible to construct such a column? Regards Katherine [[alternative HTML version deleted]]
?rep On Wed, Apr 17, 2013 at 11:11 AM, Katherine Gobin <katherine_gobin@yahoo.com> wrote:> Dear R forum > > I have a data.frame > > df = data.frame(dates = c("4/15/2013", "4/14/2013", "4/13/2013", > "4/12/2013"), values = c(47, 38, 56, 92)) > > I need to to create a vector by repeating the dates as > > "Current_date", 4/15/2013, 4/14/2013, 4/13/2013, 4/12/2013, > "Current_date", 4/15/2013, 4/14/2013, 4/13/2013, 4/12/2013, Current_date, > 4/15/2013, 4/14/2013, 4/13/2013, 4/12/2013 > > i.e. I need to create a new vector as given below which I need to use for > some other purpose. > > Current_date > 4/15/2013 > 4/14/2013 > 4/13/2013 > 4/12/2013 > Current_date > 4/15/2013 > 4/14/2013 > 4/13/2013 > 4/12/2013 > Current_date > 4/15/2013 > 4/14/2013 > 4/13/2013 > 4/12/2013 > > Is it possible to construct such a > column? > > Regards > > Katherine > > > > [[alternative HTML version deleted]] > > > ______________________________________________ > R-help@r-project.org mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > >[[alternative HTML version deleted]]
Hello, Try the following. rep(c("Current_date", as.character(df$dates)), 3) Hope this helps, Rui Barradas Em 17-04-2013 10:11, Katherine Gobin escreveu:> Dear R forum > > I have a data.frame > > df = data.frame(dates = c("4/15/2013", "4/14/2013", "4/13/2013", "4/12/2013"), values = c(47, 38, 56, 92)) > > I need to to create a vector by repeating the dates as > > "Current_date", 4/15/2013, 4/14/2013, 4/13/2013, 4/12/2013, "Current_date", 4/15/2013, 4/14/2013, 4/13/2013, 4/12/2013, Current_date, 4/15/2013, 4/14/2013, 4/13/2013, 4/12/2013 > > i.e. I need to create a new vector as given below which I need to use for some other purpose. > > Current_date > 4/15/2013 > 4/14/2013 > 4/13/2013 > 4/12/2013 > Current_date > 4/15/2013 > 4/14/2013 > 4/13/2013 > 4/12/2013 > Current_date > 4/15/2013 > 4/14/2013 > 4/13/2013 > 4/12/2013 > > Is it possible to construct such a > column? > > Regards > > Katherine > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > R-help at r-project.org mailing list > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
On 04/17/2013 07:11 PM, Katherine Gobin wrote:> Dear R forum > > I have a data.frame > > df = data.frame(dates = c("4/15/2013", "4/14/2013", "4/13/2013", "4/12/2013"), values = c(47, 38, 56, 92)) > > I need to to create a vector by repeating the dates as > > "Current_date", 4/15/2013, 4/14/2013, 4/13/2013, 4/12/2013, "Current_date", 4/15/2013, 4/14/2013, 4/13/2013, 4/12/2013, Current_date, 4/15/2013, 4/14/2013, 4/13/2013, 4/12/2013 > > i.e. I need to create a new vector as given below which I need to use for some other purpose. > > Current_date > 4/15/2013 > 4/14/2013 > 4/13/2013 > 4/12/2013 > Current_date > 4/15/2013 > 4/14/2013 > 4/13/2013 > 4/12/2013 > Current_date > 4/15/2013 > 4/14/2013 > 4/13/2013 > 4/12/2013 > > Is it possible to construct such a > column? >Hi Katherine, How about: rep(c("Current date",paste(4,15:12,2013,sep="/")),3) Jim