r function/loop to add column and value to multiple dataframes

前端 未结 3 1172
终归单人心
终归单人心 2020-12-20 02:46

I have 8 data frames that I want to add a column called \'park\', then fill this column in w/ a value that comes from the last four characters of the data

3条回答
  •  星月不相逢
    2020-12-20 03:31

    A variation using Map and some "[<-" trickery:

    vars <- ls(pattern="water_.")
    l <- mget(vars)
    names(l) <- substr(vars,nchar(vars)-3,nchar(vars))
    do.call(rbind,Map("[<-",l,TRUE,"park",names(l)))
    

提交回复
热议问题