I have a function to select a value from a dataframe. I want to select that value, save it, remove it from the dataset, and select a value using the same function from the remaining values in the dataframe. What is the best way to do this?
Here is a simple example:
V1 <- c(5,6,7,8,9,10) df <- data.frame(V1) V2 <- as.data.frame(matrix(nrow=3,ncol=1)) maximum <- function(x){ max(x) } V2[i,]<- maximum(df) df <- anti_join(df,V2,by='V1')
How can I set this up such that I reapply the maximum function to the remaining values in df and save these values in in V2?
(Also, I'm using a different and more complex set of functions and if/else statements than max - this is just an example. I do have to reapply the function to the remaining values, because I will be using the function on a new dataframe if df is empty).
https://stackoverflow.com/questions/65418499/extract-a-value-from-a-dataframe-iteratively-r December 23, 2020 at 11:04AM
没有评论:
发表评论