Hi,
I was curious whilst learning and reading these posts:
https://community.rstudio.com/t/return-the-first-position/90407/7
and this post:
https://community.rstudio.com/t/help-deleting-value-in-a-list-greater-than-10/52113/4
and I started with this:
x <- data.frame(x = c(2, 5, 4, 4, 5, 5, 5, 5))
which(x > 4)
So it gives me an indices of values that are greater than 4.
I would like to have a data frame that first column is like in original x data frame:
View(x)

and in next created column that will be indices of values that are greater than 4, and then in next column will be a column with real values greater than 4. All other cells will be filled with NA.
So I tried:
greater_than_4<-lapply(x,function(x)which(x > 4))
that gives me a list with indices of values, that are greater than 4 (but maybe purrr would be better than lapply), and this:
which(x > 4, arr.ind = TRUE) %>% as.data.frame()
# or:
vector_in_one_column <- as.data.frame(t(greater_than_4))
gives me a data frame with indices.
And next command gives me values, not indices:
x[x>4]
I would like to ask for advice how to glue it together into one dataframe ?
Thanks