With R, loop over data frames, and assign appropriate names to objects created in the loop

后端 未结 3 1779
一生所求
一生所求 2020-12-28 22:48

This is something which data analysts do all the time (especially when working with survey data which features missing responses.) It\'s common to first multiply impute a se

3条回答
  •  北荒
    北荒 (楼主)
    2020-12-28 23:13

    Another approach is to use the plyr package to do the looping. Using the example constructed by @chl, here is how you would do it

    require(plyr)
    
    # read csv files into list of data frames
    data_frames = llply(csvdat, read.csv)
    
    # run regression models on each data frame
    regressions = llply(data_frames, lm, formula = y ~ .)
    names(regressions) = csvdat
    

提交回复
热议问题