Hello Vishal 
Maybe this is what you want?

x<-c(0.34,0.36,3)
y<-c(0.56,0.76,4)
a<-data.frame(x,y)
>a
     x    y
1 0.34 0.56
2 0.36 0.76
3 3.00 4.00

a$diff<-(log(a$x))
 a$diff2<-(log(a$y))
>a
     x    y      diff      diff2
1 0.34 0.56 -1.078810 -0.5798185
2 0.36 0.76 -1.021651 -0.2744368
3 3.00 4.00  1.098612  1.3862944
 
and if you wnat to  coerce the first row to a whatever
value just type
a[1,]<-NA


Cheers 
A
 


----- Messaggio originale -----
Da: Vishal Belsare <[EMAIL PROTECTED]>
A: r-help@r-project.org
Inviato: Mercoledì 9 gennaio 2008, 23:16:38
Oggetto: [R] diff in a dataframe

I have a dataframe say:

date   price_g   price_s
         0.34        0.56
         0.36        0.76
           .              .
           .              .
           .              .

and so on. say, 1000 rows.

Is it possible to add two columns to this dataframe, by computing say
diff(log(price_g) and diff(log(price_s)) ?

The elements in the first row of these columns cannot be computed, but
can I coerce this to happen and assign a missing value there? It would
be really great if I could do that, because in this case I don't have
to re-index my transformed series to the dates again in a new
dataframe.

Thanks in anticipation.


Vishal Belsare

______________________________________________
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.






      ___________________________________ 

ttp://it.docs.yahoo.com/nowyoucan.html
        [[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.

Reply via email to