Skip to content
Prev 29226 / 29559 Next

Finding the highest and lowest rates of increase at specific x value across several time series in R

"df" is not an object, but is an input to a function (known as a function argument). If you run the code for the "ExtractFirstMin" function definition with a clear environment you'll notice there's no error event though there's no object df. What will happen after you run the code is a new variable called "ExtactFirstMin" will be defined. This is new variable in your environent is actually a function. It works just like any built in R function such as "mean", "range", "min", etc, but it only exists because you defined it. When you supply an input to the function it is substituted for "df" in that function code. When you use "sapply" you input a list of all your data frames as well as the function to apply to them. So when you do sapply(df_list, ExtactFirstMin), you are applying that ExtractFirstMin function across all of your dataframes.  You should only need to edit the right side of the following line of code to put your dataframes in the list by substituting the names of your dataframes:

df_list<- list(dataframe1, dataframe2, dataframe3, dataframe4, dataframe5, dataframe6, dataframe7, dataframe8, dataframe9, dataframe10)

You do not need the code block to create 10 data frames. Since I don't have your data, I needed to generate data with a similar structure to run the code on, but you can run the code on your real data.

Here are some resources on functions and iteration that may help clarify a few things.
https://r4ds.had.co.nz/functions.html
https://r-coder.com/sapply-function-r/
Message-ID: <BN0PR08MB73419B377D0F00EC2A22879FC67F9@BN0PR08MB7341.namprd08.prod.outlook.com>
In-Reply-To: <1626241313.3247434.1684353383224@mail.yahoo.com>