2017-05-23 9 views
1

왜이 기능이 작동하지 않는지 설명 할 수 있습니까?

structure(list(`lagged Date` = structure(c(1466306880, 1466307060, 
1466307240, 1466307420, 1466307600, 1466307780), class = c("POSIXct", 
"POSIXt"), tzone = "UTC"), Location = c(309, 309, 309, 309, 309, 
309), Duration = c(0, 0, 0, 0, 0, 0), Latitude = c(53.50205667, 
53.501915, 53.50183667, 53.50178833, 53.50184, 53.50186167), 
    Longitude = c(-3.354733333, -3.354096667, -3.353838333, -3.353673333, 
    -3.353711667, -3.353741667), `Number of Records` = c(1, 1, 
    1, 1, 1, 1), Speed = c(0.9, 0, 0, 0, 0, 0), `Sum of Var` = c(38, 
    38, 38, 38, 38, 38), check = c(0, 0, 0, 0, 0, 0)), .Names = c("lagged Date", 
"Location", "Duration", "Latitude", "Longitude", "Number of Records", 
"Speed", "Sum of Var", "check"), row.names = c(NA, -6L), class = c("tbl_df", 
"tbl", "data.frame")) 

Error in match.fun(FUN) : 'diff(dat$ lagged Date)' is not a function, character or symbol

가 감사 :

tapply(dat$`lagged Date`, INDEX = dat$Location, FUN = diff(dat$`lagged Date`)) 

나는 다음과 같은 오류가 나타날 수 있습니다!

답변

0

은 당신이 무엇을 달성하고자하는 확실하지만, 단지 FUN 부품 작품으로 diff를 사용하지 않는이 출력 생성 : 당신이 hours로 출력을 변환 할 경우

tapply(dat$`lagged Date`, INDEX = dat$Location, FUN = diff) 

$`309` 
Time differences in mins 
[1] 3 3 3 3 3 

것은, 당신이 그렇게 할 수 있습니다 그리고 difftime -list 객체의 값을 선택하여 그 변환 :

:

as.numeric(tapply(dat$`lagged Date`, INDEX = dat$Location, FUN = diff)[[1]], units = "hours") 

출력은 다음과 같습니다

[1] 0.05 0.05 0.05 0.05 0.05 
+0

예. 그렇지만 시차는 초 단위가 아닙니다. 나는 몇 시간 안에 그것을 갖고 싶다. 가능한가? –

+0

흠, 출력 내용이 어떻게 될지에 따라 다릅니다. 내 편집을 참조하십시오. – LAP