如何检查列中的第一个和最后一个非零值并返回其在数据框中的位置。
附件是我正在使用的数据框。
structure(list(`Row Labels` = c("2019-01-01", "2019-02-01", "2019-03-01",
"2019-04-01", "2019-05-01", "2019-06-01", "2019-07-01", "2019-08-01",
"2019-09-01", "2019-10-01", "2019-11-01", "2019-12-01", "2020-01-01",
"2020-02-01", "2020-03-01", "2020-04-01", "2020-05-01", "2020-06-01",
"2020-07-01", "2020-08-01", "2020-09-01", "2020-10-01", "2020-11-01",
"2020-12-01", "2021-01-01", "2021-02-01", "2021-03-01", "2021-04-01",
"2021-05-01", "2021-06-01", "2021-07-01", "2021-08-01", "2021-09-01",
"2021-10-01", "2021-11-01", "2021-12-01", "2022-01-01", "2022-02-01",
"2022-03-01", "2022-04-01", "2022-05-01", "2022-06-01", "2022-07-01",
"2022-08-01", "2022-09-01", "2022-10-01"), `XYZ|551` = c(0, 0,
0, 0, 0, 0, 0, 0, 0, 206, 1814, 2324, 772, 1116, 1636, 1906,
957, 829, 911, 786, 938, 1313, 2384, 1554, 1777, 1635, 1534,
1015, 827, 982, 685, 767, 511, 239, 1850, 1301, 426, 261, 201,
33, 0, 0, 0, 0, 0, 0)), row.names = c(NA, -46L), class = c("tbl_df",
"tbl", "data.frame"))
如果你能根据检查结果找到酒店的位置,你会很有帮助的。谢谢。
2条答案
按热度按时间kb5ga3dv1#
以R为底数的话可能是这样的:
输入:
创建于2022年12月19日,使用reprex v2.0.2
gt0wga4j2#
您可以执行以下操作: