Dealing with repetitive tasks in R

后端 未结 3 742
春和景丽
春和景丽 2020-12-28 17:35

I often find myself having to perform repetitive tasks in R. It gets extremely frustrating having to constantly run the same function on one or more data structures over and

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-28 18:14

    As a general guideline, if you have several objects that you want to apply the same operations to, you should collect them into one data structure. Then you can use loops, [sl]apply, etc to do the operations in one go. In this case, instead of having separate data frames df1, df2, etc, you could put them into a list of data frames and then run na.omit on all of them:

    dflist <- list(df1, df2, <...>)
    dflist <- lapply(dflist, na.omit)
    

提交回复
热议问题