Skip to content
Prev 200805 / 398503 Next

re placing the dates format in R for exporting the data set...

On Nov 18, 2009, at 11:00 PM, ychu066 wrote:

            
replace needs its first argument to be a vector, while you have given  
it a dataframe.

Look at these examples:
 > toms <- data.frame(a=letters[1:10], b=Sys.Date() + 1:10)
 > toms
    a          b
1  a 2009-11-20
2  b 2009-11-21
3  c 2009-11-22
4  d 2009-11-23
5  e 2009-11-24
6  f 2009-11-25
7  g 2009-11-26
8  h 2009-11-27
9  i 2009-11-28
10 j 2009-11-29
 > replace(toms$b, toms$b=="2009-11-23", 6)
Error in as.Date.numeric(value) : 'origin' must be supplied

Notice that this did not
 > replace(toms$b, toms$b=="2009-11-23", "2008-01-01")
  [1] "2009-11-20" "2009-11-21" "2009-11-22" "2008-01-01" "2009-11-24"  
"2009-11-25" "2009-11-26"
  [8] "2009-11-27" "2009-11-28" "2009-11-29"
 > toms
    a          b
1  a 2009-11-20
2  b 2009-11-21
3  c 2009-11-22
4  d 2009-11-23
5  e 2009-11-24
6  f 2009-11-25
7  g 2009-11-26
8  h 2009-11-27
9  i 2009-11-28
10 j 2009-11-29

Notice that the replace() operation did not do anything to "toms". If  
you had wanted it to, you would have needed to do:

toms$b <- replace(toms$b, toms$b=="2009-11-23", "2008-01-01")

Now, if you want further assistance you need to provide a working  
excaple that has the same features as your problem. Use str(toms_dat)  
to see what type your columns are ant then perhaps:

dput(head(toms_dat))

or:

dump("toms_dat", file=stdout() )

or if toms_dat is big, then:

smalltoms <- head(toms_dat)
dump("smalltoms", stdout() )
David Winsemius, MD
Heritage Laboratories
West Hartford, CT