[R] Dynamic resizing of lists, dataframes (newbie question)

Uwe Ligges ligges at statistik.uni-dortmund.de
Mon May 20 11:49:50 CEST 2002


Neil Osborne wrote:
> 
> Hi All,
> 
> I would be very grateful for some help with finding my way around R.
> (I'm sure some of this is in the manual - but I just need to try some ideas
> out and I don't want to spend hours going through reams of text - BTW, I
> have checked the manual, and the stuff I want to do here is not covered
> explicitly ...)
> 
> This is a snippet of pseudo code  showing what I want to do in R
>
> 1).
> #declare a dataframe (actually a time series)
> mydata <- #declare a dataframe to hold date, value pairs (i.e. two columns)

[Some answers after the private message]

Use 
 data.frame()


> 2)
> #dynamically size the dataframe and add a value
> mydata[length(mydata) +1 ] <- #new date value pair

Almost right, try:
 mydata[length(mydata) + 1, ]
or
 cbind()
 

> 3)
> #find the first occurence (date) on which a value occured
> foo <- function(mydata, value) {
> for (i in mydata)
> {
>    if (mydata[i] == value )
>         #return x$date[i] ?
> }

 which(mydata == value)[1]

Uwe Ligges
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list