![](/img/trans.png)
[英]How to loop through all columns and rows in 2 dataframes within existing R function
[英]How to loop through dataframes and delete empty columns (in R)?
我想使用 for 循環或 lapply 刪除多個數據幀的空列。
我的數據框總是以“test.xxx”開頭。
如果我如下一一進行,它可以工作。
test.acc_consoles2 <- Filter(function(x)!all(is.na(x) || is.null(x) || x == "" || x == 0), test.acc_consoles2)
但是,如果我使用 for loop 或 lapply,它就不起作用。 我已經嘗試了以下代碼。
for(i in lst) {
i <- Filter(function(x)!all(is.na(x) || is.null(x) || x == "" || x == 0),x=i)
}
我想要沒有空列的干凈數據框。 由於有 189 個數據幀,我想使用 lapply 或 for 循環。
我們可以使用lapply
並過濾列表中每個 dataframe 的列
output <- lapply(lst, function(df)
Filter(function(x)!all(is.na(x) || is.null(x) || x == "" || x == 0),df))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.