I am new to R and this is a very simple question. I found a lot of similar things that I want, but not quite like that. Basically, I have several frames of data, and I just want to run the same function for all of them. It may work for a loop, but I'm not sure how to properly configure it to call data frames. It also seems that most prefer a lappish approach with R. I played with the get function, but to no avail. I apologize if this is a duplicate question. Any help would be greatly appreciated!
Here is my simplified simplified example: 2 data frames: df1, df2
df1 start stop ID 0 10 x 10 20 y 20 30 z df2 start stop ID 0 10 a 10 20 b 20 30 c
what i want is 4th column with average start and stop value for both dfs
df1 start stop ID Avg 0 10 x 5 10 20 y 15 20 30 z 25
I can make this one data frame at a time:
df1$Avg <- rowMeans(subset(df1, select = c(start, stop)), na.rm = TRUE)
but I want to run it on all data frames.
for-loop r dataframe lapply
user3272284
source share