R 데이터프레임 시간 계산

1 개요[ | ]

R 데이터프레임 시간 계산
R 데이터프레임 기간 계산
R 데이터프레임 difftime 구하여 컬럼 추가

2 예제1: 분 단위 (기본)[ | ]

df <- read.csv( header=T, stringsAsFactors=F, text="
session,started,finished,user
1,2019-06-01 01:00,2019-06-01 01:10,alice
2,2019-06-01 02:00,2019-06-01 02:30,bob
3,2019-06-01 03:00,2019-06-01 04:00,carol
4,2019-06-01 04:00,2019-06-01 05:20,alice
5,2019-06-01 05:00,2019-06-01 04:50,bob
")
df
df$started <- as.POSIXct(df$started)
df$finished <- as.POSIXct(df$finished)
df$duration <- df$finished - df$started
df
df[df$duration < 60,]

3 예제2: 일 단위[ | ]

df <- read.csv( header=T, stringsAsFactors=F, text="
session,started,finished,user
6,2019-06-01 01:00,2019-06-01 01:10,david
7,2019-06-01 02:00,2019-06-02 02:30,erin
8,2019-06-01 03:00,2019-06-03 04:00,frank
9,2019-06-01 04:00,2019-06-04 05:20,david
10,2019-06-01 05:00,2019-06-05 04:50,erin
")
df
df$started <- as.POSIXct(df$started)
df$finished <- as.POSIXct(df$finished)
df$duration <- as.numeric(df$finished - df$started, units="days")
df

4 같이 보기[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}