2017-02-27 1 views
0

매우 간단한 공식을 사용하여 어떻게 순간 속도를 계산할 수 있습니까?순간 속도 - 이전 값 참조

Vi = V0 + acceleration * time 

다음 작업은 MS.Excel에서 이전 이전 셀을 클릭 할 수 있기 때문에 매우 쉽지만 R에서 이것을 어떻게 호출합니까?

acceleration <- c(1,2,3,4,5,4,3,2,1) 
time <- rep(0.1,9) 
df1 <- data.frame(acceleration, time) 


df1$instant.vel <- df1$acceleration * df1$time + .... 
+0

는 DF1의 속도에 대한 열이인가를? – OmaymaS

+0

우리가 얻고 자하는 것 – lukeg

+1

은 v0 = 0이라고 가정하고, cumsum (df1 $ acceleration * df1 $ time)은 원하는 것을 제공합니까? –

답변

0

dplyr::lag

library(dplyr) 

df1 %>% 
    mutate(V=(lag(acceleration,default=0)*lag(time,default=0))+(acceleration*time)) 

    acceleration time V 
1   1 0.1 0.1 
2   2 0.1 0.3 
3   3 0.1 0.5 
4   4 0.1 0.7 
5   5 0.1 0.9 
6   4 0.1 0.9 
7   3 0.1 0.7 
8   2 0.1 0.5 
9   1 0.1 0.3 

또는 단계별로 사용해보십시오 :

df1 %>% 
    mutate(V0=(acceleration*time)) %>% 
    mutate(V1=V0+(lag(acceleration,default=0)*lag(time,default=0))) 
    acceleration time V0 V1 
1   1 0.1 0.1 0.1 
2   2 0.1 0.2 0.3 
3   3 0.1 0.3 0.5 
4   4 0.1 0.4 0.7 
5   5 0.1 0.5 0.9 
6   4 0.1 0.4 0.9 
7   3 0.1 0.3 0.7 
8   2 0.1 0.2 0.5 
9   1 0.1 0.1 0.3