Skip to content

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

8 messages · ychu066, jim holtman, David Winsemius

#
hi everyone, i am having difficulties with replacing the dates format in R
for exporting the data set...

eg: the code that i used was 
toms_dat<- replace(toms_dat, toms_dat ==2009-08-06, 2)
toms_dat<- replace(toms_dat, toms_dat ==2009-08-04, 1)

but when i export the data as into txt file or excel file the dates come up
with very large numbers .....:drunk:

please help me ...=)
#
moreover, how come when I export a dataframe out from R say, it become a
excel file.  The first column includes the inex number eg: 1,2,3 ......n
instead of including the values that the first column should be have ....

anyone know how to solve this problem ?
ychu066 wrote:

  
    
#
Moreover,  I want to rename the column name V1,V2,V3,V4.....V146.  how do i
write the code in R ???

thanks everyone that look at the thread/
ychu066 wrote:
http://old.nabble.com/file/p26400792/what.csv what.csv
#
First of all '2009-08-06' is 1995; this is probably not what you were
expecting.  What do you what your expression to do?  Is 'toms_dat' a
dataframe?  if so, your expression 'toms_dat ==2009-08-06' seem
strange.  So tell us what you want to do, not how you want to do it.
On Tue, Nov 17, 2009 at 4:54 PM, ychu066 <ychu066 at aucklanduni.ac.nz> wrote:

  
    
#
?write.table

If you read the help file, and do a little experimenting, you will see
that there is a parameter 'rownames=FALSE' that may answer your
question.

Also since you did not have column names on your input, you get V1,
V2,...  You can put your own column names.  It helps again to read the
help file on 'read.table' and look at the parameter 'col.names'.
There is also the colnames function.  It also might help to (re)read
the Intro to R.
On Tue, Nov 17, 2009 at 8:27 PM, ychu066 <ychu066 at aucklanduni.ac.nz> wrote:

  
    
#
Ok thanks
jholtman wrote:

  
    
#
hey Jim ,

I have solve the column name problems now.  But i am still unable to read
the date in R ...

toms_dat<- replace(toms_dat, toms_dat ==2009-08-24, 6)

the toms_dat is a data frame , and I  want to replace the date to be a
single number eg:1,2,3, ....

regards,
Tom.
jholtman wrote:

  
    
#
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