If the value of on column reaches or exceeds certain value, give value of the same row but another column

Hello,
I'm quite new to R and need some help please.

There is a data frame for the growth of a certain plant with 2 columns. One shows the days (1, 2, 3, 4...) and one shows the weight of a plant.

I would like to have a code, that gives the day at which the mass reaches or exceeds 350g.
In other words, if value of weight-column reaches or exceeds 350, then give the value of the first column.

Regards,
Zauberfarn

library(tidyverse)

(example_df <- tibble(d=1:10,
                      w=5+(1:10)^2))

(result <- example_df %>%
    summarise(day = min(case_when(w>50 ~ d,
                              TRUE ~ NA_integer_),
                        na.rm=TRUE)))
1 Like

Thank you very much nirgrahamuk, I'll try to understand every step. Seems to work well :slight_smile:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.