Re: [R] dataframe: how to select an element from a row

2012-01-20 Thread ikuzar
This works but I do not know if there is a better way tmp = df[df$myvalue<2000,] ind = match(tmp$myvalue, df$myvalue) res = df$DateTime[ind] solution = list(ind[1], res[1]) -- View this message in context: http://r.789695.n4.nabble.com/dataframe-how-to-select-an-element-from-a-row-tp4311881p43

Re: [R] dataframe: how to select an element from a row

2012-01-20 Thread ikuzar
Thank you Jorge and Florent for your responses. Now, I 'd like to get the date *(and its index) *where myvalue < 2000 for the first time. I expect for a result like (index, date) = (3, 2012-01-07 ) This way does not work: ind = match(df$myvalue <2000, df$myvalue) res = df$DateTime[ind] -- View

Re: [R] dataframe: how to select an element from a row

2012-01-19 Thread Jorge I Velez
Thank you Florent, it really helps. Regards, Jorge.- On Thu, Jan 19, 2012 at 7:28 PM, Florent D. <> wrote: > Another possibility: > > df$Date[match(1800, df$myvalue)] > > match() stops at the first value encountered so it may be a bit faster > than a full subset(), depending on your table size.

Re: [R] dataframe: how to select an element from a row

2012-01-19 Thread Florent D.
Another possibility: df$Date[match(1800, df$myvalue)] match() stops at the first value encountered so it may be a bit faster than a full subset(), depending on your table size. Another difference: this approach would return NA if there was no match, subset(...)[1, ] would trigger an error. Depend

Re: [R] dataframe: how to select an element from a row

2012-01-19 Thread Jorge I Velez
Hi ikuzar, Try subset(df, myvalue == 1800, select = Date)[1, ] See ?subset for more information. HTH, Jorge.- On Thu, Jan 19, 2012 at 6:42 PM, ikuzar <> wrote: > Hi, > I 'd like to select the Date where myvalue =1800 appears the* first time*. > > For instance: > df =data.frame(date, myvalue,