Neil Osborne
2002-May-19 19:34 UTC
[R] Dynamic resizing of lists, dataframes (newbie question)
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) 2) #dynamically size the dataframe and add a value mydata[length(mydata) +1 ] <- #new date value pair 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] ? } _________________________________________________________________ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Uwe Ligges
2002-May-20 09:49 UTC
[R] Dynamic resizing of lists, dataframes (newbie question)
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 pairAlmost 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Apparently Analagous Threads
- Match strings across two differently sized dataframes and copy corresponding row to dataframe
- aggregate function with a dataframe for both "x" and "by"
- How to findout the name of a dataframe
- dividing a dataframe column by different constants
- Replace selected columns of a dataframe with NA