R 데이터프레임 특정기간 추출

Jmnote bot (토론 | 기여)님의 2021년 4월 8일 (목) 23:15 판 (봇: 자동으로 텍스트 교체 (-<source +<syntaxhighlight , -</source> +</syntaxhighlight>))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

R 데이터프레임 특정기간 추출

2 날짜(Date)[ | ]

df <- read.table( header=T, sep=",", stringsAsFactors=FALSE, text="
date,fruit,ea
2019-05-30,apple,1
2019-06-01,apple,1
2019-06-03,banana, 2
2019-06-05,apple,3
2019-06-06,banana,4
")
df$date <- as.Date(df$date)
newdf <- df["2019-06-01" <= df$date & df$date <= "2019-06-05",]
newdf

3 날짜시간(POSIXct)[ | ]

df <- read.table( header=T, sep=",", stringsAsFactors=FALSE, text="
dt,fruit,ea
2019-05-30 13:00,apple,1
2019-06-01 13:00,apple,1
2019-06-03 13:00,banana, 2
2019-06-05 13:00,apple,3
2019-06-06 13:00,banana,4
")
df$dt <- as.POSIXct(df$dt)
newdf <- df["2019-06-01 12:00" <= df$dt & df$dt < "2019-06-05 12:00",]
newdf

4 같이 보기[ | ]

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