我正在嘗試確定我的每個列記錄值的天數。它們都在不同的時間開始/停止記錄,重要的是計算的總天數不包括列有 NA 的時間。這是我的資料框的示例
df = structure(list(Date_Time_GMT_3 = structure(c(1594233000, 1594533900, 1597235700,
1595234800, 1594336600, 1595237500),
class = c("POSIXct", "POSIXt"), tzone = "EST"),
`20874285_33MR` = c(14.996, 15.091, 15.187, 15.282, 15.378, 15.378),
`20874290_103MR` = c(NA_real_, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_),
`20874287_102MR` = c(NA_real_, 15.091, 15.187, 15.282, NA_real_, NA_real_),
`20874299_54MR` = c(NA_real_, 15.378, 15.378, NA_real_, NA_real_, NA_real_),
`20874316_AIR_90MR` = c(NA_real_, NA_real_, NA_real_,15.091, 15.187, 15.282)),
row.names = c(NA, 6L), class = "data.frame")
時間無所謂。只要那天有記錄,我就可以算作有1天記錄的列。
最終結果應該有每列的總天數
uj5u.com熱心網友回復:
這是你想做的嗎?
library(dplyr)
df %>%
group_by(date = as.Date(Date_Time_GMT_3)) %>%
summarise(across(everything(), ~any(!is.na(.)))) %>%
summarise(across(-date, sum))
#> # A tibble: 1 x 6
#> Date_Time_GMT_3 `20874285_33MR` `20874290_103MR` `20874287_102MR` `20874299_54MR` `20874316_AIR_90MR`
#> <int> <int> <int> <int> <int> <int>
#> 1 5 5 0 3 2 2
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/454410.html
上一篇:多種顏色的小提琴情節
下一篇:替換字串會導致名稱不正確
