When I calculate row means foreach dataset in a list, I want that the name of this new variable (avg) differs for each element of the list, e.g., something like avg_df1
, avg_df2
, or it takes a part of the dataset name and declares it as a variable name. Can it be done by using the "paste" function?
list = list(df1, df2)
list = lapply(list, function(x){
x$avg = rowMeans(x[,-2])
x
})