Hello,

this little example my work for demo purposes:


x1 = runif(45)
x2 = runif(45)
x3 = runif(45)
df = data.frame(x1=x1,x2=x2,x3=x3)

test <- function(df, values, n) {
if (nrow(df) < n) {
 df <- rbind(df, values)
} else {
df[1:(nrow(df)-1),] <- df[2:nrow(df),]
 df[n,] <- values
}
return(df)
}

for (i in 1:10) {
 df <- test(df, rep(1, ncol(df)), 50)
}

The demo is not exactly what you specified, as a dataframe cannot have
different number of observations in columns/variables, so I modified it to
update it with a "full" observation (=row) each run.

Gergely

On Tue, Jan 11, 2011 at 6:14 AM, antujsrv <antuj...@gmail.com> wrote:

>
> my dataset looks like :
>
> >df
>
>   VIX   GLD   FAS
> 1    2     4      5
> 2    8     9      10
> 3    56   9       98 .. continued
>
> the dataset has n observations which is fixed and i need to create a
> function :
>
> test <- function(variable name, value) -- this function has to insert the
> value under the respective variable and if the column length exceeds "n"
> then automatically the first value from the top of the variable should get
> deleted, the way we have in stacking-first in first out.
>
> Any help writing this function would be highly appreciated
> Thanks
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Real-time-dataset-tp3208473p3208473.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>

        [[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