Re: [R] diff in a dataframe

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Thu, 10 Jan 2008 08:23:02 -0200

Perhaps you can do this:

cbind(df, sapply(rbind(c(NA, NA),log(df)), diff))

On 10/01/2008, Vishal Belsare <shoot.spam_at_gmail.com> wrote:
> 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_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.
>

-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

______________________________________________
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.
Received on Thu 10 Jan 2008 - 10:27:55 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 10 Jan 2008 - 10:30:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive