DataScience
article thumbnail
728x90

 

 

basic2.csv
0.02MB

 

주어진 데이터에서 2022년 5월 주말과 평일의 sales컬럼 평균값 차이를 구하시오 (소수점 둘째자리까지 출력, 반올림)

library(dplyr)
library(lubridate)
df<-read.csv('../input/bigdatacertificationkr/basic2.csv')
df1<-df%>%mutate(year=year(Date),month=month(Date),wday=wday(Date))
	%>%filter(year==2022&month==5)
weekend<-df1%>%filter(wday==1|wday==7)
weekday<-df1%>%filter(!(wday==1|wday==7))
ans<-round(abs(mean(weekday$Sales,na.rm=T)-mean(weekend$Sales,na.rm=T)),2)
print(ans)

#정답 : 3010339.1

 

 

암기

library(lubridate)

날짜 lubridate wday() wday(Date,label=T) #labet=T return값:sun, mon, tue, wed
                                      #label=F return값:1~7

 

 

profile

DataScience

@Ninestar

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!