Na.Approx具有多个特定列
我有一个带有许多列(Cola,Colb,Colc,Cold,Cold……)的DataFrame(DF)。我想将Na.AppRox函数和group_by应用于数据框架中的几个(但不是全部)列。我成功地在一列上应用了Na.Approx和group_by函数,并具有以下内容:
dfxna< -df%>%group_by(cola)%>%突变(colb = na.approx(colb,na.rm,na.rm) = false,maxGap = 4))
但是,我无法创建适用于几个(指定的列)的代码。我认为Lapply是合适的,并且尝试使用Lapply几次。
I have a dataframe (DF) with many columns (colA, colB, colC, colD, . . . . ). I would like to apply the na.approx function, with group_by, to several, but not all, columns in the dataframe. I succeeded in applying the na.approx and group_by functions on one column with the following:
DFxna<-DF %>% group_by(colA) %>% mutate(colB = na.approx(colB, na.rm = FALSE, maxgap=4))
However, I was not able to create a code that would apply to several, specified, columns. I thought that lapply would be appropriate, and tried several times, unsuccesfully, to use lapply.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许这适合您的需求。正如我在评论中提到的那样,一个选项是使用
dplyr ::跨
。使用一些虚假数据:
Maybe this fits your need. As I mentioned in my comment one option would be to use
dplyr::across
.Using some fake data: