[R] Simple Model in R

Rui Barradas ruipbarradas at sapo.pt
Sat Sep 7 10:41:08 CEST 2013


Hello,

Try the following.

dat <- read.table(text = "
Date                                Value
08/01/2013                        100
08/02/2013                         100.5
08/03/2013                         102
", header = TRUE)


dat$New <- c(NA, diff(dat$Value))
dat


Hope this helps,

Rui Barradas

Em 07-09-2013 06:06, Ankur Seth escreveu:
> Hello All,
>
> I am trying to build a model in R. I am facing the following problem...
>
> My Data Frame contains the following data...
>
> Date                                Value
> 08/01/2013                        100
> 08/02/2013                         100.5
> 08/03/2013                         102
> ....
>
> Now I want to add a column to this data frame where New Column Value =
> Difference of two subsequent observations. For Eg. on 08/02/2013 the new
> value = 100.5 - 100=0.5
>
> I want to do this dynamically such that if I change the value in Value
> column the new column should recalculate automatically.
>
> Is there a way to do this in R?
>
> Regards,
> Ankur Seth
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list