#-------[CCTV location info]----------------------
cctv3 <- cctv1[4:nrow(cctv1),c(1,2,4)]
#View(cctv3)
names(cctv3) <- c("ku","Y2011","Y2012")
cctv3$ku <- as.character(cctv3$ku)
cctv3$Y2011<-gsub(",","",as.character(cctv3$Y2011))
cctv3$Y2011 <- as.numeric(cctv3$Y2011)
cctv3$Y2012<-gsub(",","",as.character(cctv3$Y2012))
cctv3$Y2012 <- as.numeric(cctv3$Y2012)
cctv4 <- cbind(cctv2[3,c(3:9)], cctv2[6,c(1:9)], cctv2[9,c(1:9)] )
cctv41 <- cbind(cctv2[2,c(3:9)], cctv2[5,c(1:9)], cctv2[8,c(1:9)] )
cctv42<-rbind(cctv41,cctv4)
cctv5 <-t(cctv42)
# class(cctv5)
cctv5 <- as.data.frame(cctv5, row.names=F)
names(cctv5) <- c("ku","Y2014")
cctv5$ku <- as.character(cctv5$ku)
cctv5$Y2014<-gsub(",","",as.character(cctv5$Y2014))
cctv5$Y2014 <- as.numeric(cctv5$Y2014)
# 2011~12 와 2014 DF 결합
cctv6<- merge(cctv3, cctv5, by="ku", all = TRUE)
#-------------------
#-----------[Population in Seoul] -------
cctv_pop1<-read.csv("cctv_pop1.csv")
names(cctv_pop1)<-c("ku","households", "kor_men","kor_women","frgn_men","frgn_women","size","seniors")
#cctv_pop2 <- cctv_pop1[ which(cctv_pop1$ku!="합계"),]
cctv_pop2 <- sqldf('select * from cctv_pop1 where ku is not "합계" ')
cctv_pop3<-cbind(cctv_pop2[1:25,], cctv_pop2[26:50,], cctv_pop2[76:100,])
names(cctv_pop3) <- c("ku2011", "households2011", "kor_men2011", "kor_women2011", "frgn_men2011", "frgn_women2011", "size2011", "seniors2011" , "ku2012" , "households2012", "kor_men2012", "kor_women2012" , "frgn_men2012" , "frgn_women2012" , "size2012" , "seniors2012", "ku2014", "households2014", "kor_men2014", "kor_women2014" , "frgn_men2014" , "frgn_women2014" , "size2014", "seniors2014")
plot(cctv_pop3$households2011, cctv_pop3$households2014)
# write.csv(cctv_pop3,"cctv_pop3.csv")
#=================
# for 루프 사용해서 변수 계산
for (i in 1:nrow(cctv6) ) {
# rownum <- as.numeric(row.names(cctv6))
# rownum <- as.numeric(row.names(cctv6))
cctv6$Y2011a[i] <- ifelse(cctv6$Y2011[i] <300, cctv6$Y2011[i] * 2, cctv6$Y2011[i])
}
'R 데이터 분석' 카테고리의 다른 글
GT apple samsung applications (0) | 2015.06.29 |
---|---|
애플과 삼성 구글트렌드 값 비교 (0) | 2015.06.29 |
# MERGE 연습 (0) | 2015.06.26 |
R 데이터 처리 연습 _ Crashes (0) | 2015.06.26 |
R 복습 (20150626) (0) | 2015.06.26 |