dplyr의 "progress_estimated"기능이 마음에 들지만 진행 막대를 얻는 방법을 dplyr 체인에서 처리하는 방법을 알지 못합니다. 아래쪽에 코드가있는 재현 가능한 예제를 넣었습니다. dplyr 체인 내부에 진행 막대를 추가하는 방법 R
이 같은 꽤 큰 data.frame 있습니다 cdatetime latitude longitude
1 2013-01-11 06:40:00 CST 49.74697 -93.30951
2 2013-01-12 15:55:00 CST 49.74697 -93.30951
3 2013-01-07 20:30:00 CST 49.74697 -93.30951
을 나는 progress_estimated의 I는 dplyr를 얻을 수있는 라이브러리
library(dplyr)
library(StreamMetabolism)
를 사용하여 각 날짜의 일출 시간을 계산하고 싶습니다 예 :
추악한 루프 (작동)
p <- progress_estimated(nrow(test))
for (i in 1:nrow(test)){
p$tick()$print()
datetime = as.POSIXct(substr(test$cdatetime[i], 1, 20), tz = "CST6CDT")
test$sunrise[i] <- sunrise.set(test$latitude[i], test$longitude[i], datetime, "CST6CDT", num.days = 1)[1,1]
}
하지만 내 함수에서 중첩 할 수 있으므로 루프를 사용하지 않아도됩니까?
은 사용 안함 :
SunriseSet <- function(dataframe, timezone){
dataframe %>%
rowwise() %>%
mutate(# calculate the date-time using the correct timezone
datetime = as.POSIXct(substr(cdatetime, 1, 20), tz = timezone),
# Get the time of sunrise and sunset on this day, at the county midpoint
sunrise = sunrise.set(latitude, longitude, datetime, timezone, num.days = 1)[1,1])
}
어떻게 여기 진행률 표시 줄을 얻을?
test2 <- SunriseSet(test, "CST6CDT")
는 여기에 몇 가지 예제 데이터입니다 :
test <- data.frame(cdatetime = rep("2013-01-11 06:40:00", 300),
latitude = seq(49.74697, 50.04695, 0.001),
longitude = seq(-93.30951, -93.27960, 0.0001))
진행률 표시 줄도 그룹 단위로 사용할 수 있어야한다고 생각합니다. 예를 들어, 날짜를 그룹화 한 다음 각 그룹에서 변경하십시오. –