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
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
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.
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
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,
5 matches
Mail list logo