Showing
9 changed files
with
391 additions
and
0 deletions
1차전처리Code.R
0 → 100644
1 | + | ||
2 | +src_dir<-c("2010104050_박재호_졸업논문/데이터/원자료/대기오염데이터/") | ||
3 | + | ||
4 | +src_file<-list.files(src_dir) | ||
5 | +src_file | ||
6 | +src_file_cnt<-length(src_file) | ||
7 | + | ||
8 | +set_src_dir<-c("2010104050_박재호_졸업논문/데이터/대기오염데이터/1차전처리(결측치제거 및 시간변수 통일)/") | ||
9 | + | ||
10 | +#for(i in 1:src_file_cnt){ | ||
11 | + | ||
12 | +# rawdata_Set <- read.csv( | ||
13 | +# paste(src_dir,"/",src_file[i],sep=""),sep = ",",header = F,stringsAsFactors = F) | ||
14 | + | ||
15 | +# write.csv(rawdata_Set, | ||
16 | +# paste(src_dir,"/","2014~2017.csv",sep = ""), | ||
17 | +# sep = ",", | ||
18 | +# row.names = FALSE, | ||
19 | +# col.names = FALSE, | ||
20 | +# quote = FALSE, | ||
21 | +# append = TRUE) #append-> stacking임 | ||
22 | + | ||
23 | +# rm(rawdata_Set) | ||
24 | + | ||
25 | +#} | ||
26 | +# 파일 용량이 커서 실패, R의 한계 | ||
27 | + | ||
28 | +for(i in 1:src_file_cnt){ | ||
29 | + | ||
30 | + refactoring_Data<- read.csv(paste(src_dir, src_file[i], sep=""), header = F, stringsAsFactors = F) | ||
31 | + | ||
32 | + colnames(refactoring_Data)<-c("지역","측정소코드","측정소명","측정일시","SO2","CO","O3","NO2","PM10","PM25","주소") | ||
33 | + | ||
34 | + refactoring_Data[is.na(refactoring_Data)]<-0 #결측치 제거 | ||
35 | + | ||
36 | + refactoring_Data<- refactoring_Data[-1,-c(2,10,11)] #1행 제거, 3열 제거(측정소코드, PM25, 주소) | ||
37 | + | ||
38 | + ## Start of 시간변수 분해 결합##### | ||
39 | + | ||
40 | + refactoring_Date<- refactoring_Data$측정일시 | ||
41 | + | ||
42 | + year<-substr(refactoring_Date,1,4) | ||
43 | + month<-substr(refactoring_Date,5,6) | ||
44 | + day<-substr(refactoring_Date,7,8) | ||
45 | + hour<-substr(refactoring_Date,9,10) | ||
46 | + | ||
47 | + hour<-sub(pattern = "24",replacement = "00",x = hour) | ||
48 | + hour<-paste0(hour,sep=":00") | ||
49 | + | ||
50 | + refactoring_Date<-paste(year,month,sep="-") | ||
51 | + refactoring_Date<-paste(refactoring_Date,day,sep="-") | ||
52 | + refactoring_Date<-paste(refactoring_Date,hour,sep=" ") | ||
53 | + | ||
54 | + refactoring_Data$측정일시<-refactoring_Date | ||
55 | + | ||
56 | + ## End of 시간변수 분해 ##### | ||
57 | + | ||
58 | + write.csv(refactoring_Data, | ||
59 | + paste(set_src_dir,"set_", src_file[i],sep = ""), | ||
60 | + sep = ",", | ||
61 | + row.names = FALSE, | ||
62 | + col.names = FALSE, | ||
63 | + quote = FALSE, | ||
64 | + append = FALSE) | ||
65 | +} | ||
66 | + | ||
67 | +rm(i,src_dir,src_file,src_file_cnt,year,month,day,hour,refactoring_Date,refactoring_Data, set_src_dir) | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
2010104050_박재호_졸업논문.zip
0 → 100644
This file is too large to display.
2차전처리_연도별Code.R
0 → 100644
1 | + | ||
2 | + | ||
3 | +src_dir<-c("2010104050_박재호_졸업논문/데이터/대기오염데이터/1차전처리(결측치제거 및 시간변수 통일)/") | ||
4 | +src_file<-list.files(src_dir) | ||
5 | +src_file_cnt<-length(src_file) | ||
6 | + | ||
7 | +set_src_dir<-c("2010104050_박재호_졸업논문/데이터/대기오염데이터/2차전처리(지역별분할 및 곽측소 시별 통합 및 연도통합)/") | ||
8 | + | ||
9 | +LocationNameList<-read.csv("2010104050_박재호_졸업논문/데이터/대기오염데이터/1차전처리(결측치제거 및 시간변수 통일)/set_2014_1.csv") | ||
10 | +LocationNameList<-unique(LocationNameList$지역) | ||
11 | +LocationNameList_cnt<-length(LocationNameList) | ||
12 | + | ||
13 | +LocationDataList<-list() | ||
14 | + | ||
15 | + | ||
16 | +for(i in 1:src_file_cnt){ # 1:4 -> 2014년평균 5:8-> 2015년 평균, 9:12-> 2016년 평균, 1:src_file_cnt -> 전체 평ㄱ | ||
17 | + | ||
18 | + temp_Data<-read.csv(paste(src_dir, src_file[i], sep=""), stringsAsFactors = F) | ||
19 | + | ||
20 | + colnames(temp_Data)<-c("지역","측정소명","측정일시","SO2","CO","O3","NO2","PM10") | ||
21 | + | ||
22 | + temp_Data<-temp_Data[-1,] | ||
23 | + | ||
24 | + for(j in 1:LocationNameList_cnt){ | ||
25 | + | ||
26 | + if(i==1){ | ||
27 | + | ||
28 | + refactoring_Data<-subset(temp_Data,지역==LocationNameList[j]) | ||
29 | + | ||
30 | + refactoring_Data[is.na(refactoring_Data)]<-0 #결측치 제거 | ||
31 | + | ||
32 | + refactoring_Data<-data.frame( #서로다른 측정소들의 측정값을 평균으로 통합 | ||
33 | + aggregate(SO2 ~ 측정일시,refactoring_Data,mean), | ||
34 | + aggregate(CO ~ 측정일시,refactoring_Data,mean), | ||
35 | + aggregate(O3 ~ 측정일시,refactoring_Data,mean), | ||
36 | + aggregate(NO2 ~ 측정일시,refactoring_Data,mean), | ||
37 | + aggregate(PM10 ~ 측정일시,refactoring_Data,mean) | ||
38 | + | ||
39 | + ) | ||
40 | + refactoring_Data<-refactoring_Data[-c(3,5,7,9)] | ||
41 | + | ||
42 | + LocationDataList[[j]]<-refactoring_Data | ||
43 | + | ||
44 | + }else{ | ||
45 | + | ||
46 | + refactoring_Data<-subset(temp_Data,지역==LocationNameList[j]) | ||
47 | + | ||
48 | + refactoring_Data[is.na(refactoring_Data)]<-0 #결측치 제거 | ||
49 | + | ||
50 | + refactoring_Data<-data.frame( #서로다른 측정소들의 측정값을 평균으로 통합 | ||
51 | + aggregate(SO2 ~ 측정일시,refactoring_Data,mean), | ||
52 | + aggregate(CO ~ 측정일시,refactoring_Data,mean), | ||
53 | + aggregate(O3 ~ 측정일시,refactoring_Data,mean), | ||
54 | + aggregate(NO2 ~ 측정일시,refactoring_Data,mean), | ||
55 | + aggregate(PM10 ~ 측정일시,refactoring_Data,mean) | ||
56 | + | ||
57 | + ) | ||
58 | + refactoring_Data<-refactoring_Data[-c(3,5,7,9)] | ||
59 | + | ||
60 | + rbind_data<-rbind(data.frame(LocationDataList[j]),refactoring_Data) | ||
61 | + | ||
62 | + LocationDataList[[j]]<-rbind_data | ||
63 | + | ||
64 | + } | ||
65 | + } | ||
66 | + | ||
67 | +} | ||
68 | + | ||
69 | +for(i in 1:LocationNameList_cnt){ | ||
70 | + | ||
71 | + write.csv(data.frame(LocationDataList[i]), | ||
72 | + paste(set_src_dir,"전체/",LocationNameList[i],".csv",sep = ""), # 2014 or 2015 or 2016 or 전체 | ||
73 | + sep = ",", | ||
74 | + row.names = FALSE, | ||
75 | + col.names = FALSE, | ||
76 | + quote = FALSE, | ||
77 | + append = FALSE) | ||
78 | + | ||
79 | +} | ||
80 | + |
2차전처리_전체Code.R
0 → 100644
1 | + | ||
2 | + | ||
3 | +src_dir<-c("2010104050_박재호_졸업논문/데이터/대기오염데이터/1차전처리(결측치제거 및 시간변수 통일)/") | ||
4 | +src_file<-list.files(src_dir) | ||
5 | +src_file_cnt<-length(src_file) | ||
6 | + | ||
7 | +set_src_dir<-c("2010104050_박재호_졸업논문/데이터/대기오염데이터/2차전처리(지역별분할 및 곽측소 시별 통합 및 연도통합)/") | ||
8 | + | ||
9 | +LocationNameList<-read.csv("2010104050_박재호_졸업논문/데이터/대기오염데이터/1차전처리(결측치제거 및 시간변수 통일)/set_2014_1.csv") | ||
10 | +LocationNameList<-unique(LocationNameList$지역) | ||
11 | +LocationNameList_cnt<-length(LocationNameList) | ||
12 | + | ||
13 | +LocationDataList<-list() | ||
14 | + | ||
15 | +for(i in 1:src_file_cnt){ | ||
16 | + | ||
17 | + temp_Data<-read.csv(paste(src_dir, src_file[i], sep=""), stringsAsFactors = F) | ||
18 | + | ||
19 | + colnames(temp_Data)<-c("지역","측정소명","측정일시","SO2","CO","O3","NO2","PM10") | ||
20 | + | ||
21 | + set_Date<-temp_Data$측정일시 | ||
22 | + set_Date<-substr(set_Date,6,16) | ||
23 | + temp_Data$측정일시<-set_Date | ||
24 | + | ||
25 | + temp_Data<-temp_Data[-1,] | ||
26 | + | ||
27 | + for(j in 1:LocationNameList_cnt){ | ||
28 | + | ||
29 | + if(i==1){ | ||
30 | + | ||
31 | + refactoring_Data<-subset(temp_Data,지역==LocationNameList[j]) | ||
32 | + | ||
33 | + refactoring_Data[is.na(refactoring_Data)]<-0 #결측치 제거 | ||
34 | + | ||
35 | + refactoring_Data<-data.frame( #서로다른 측정소들의 측정값을 평균으로 통합 | ||
36 | + aggregate(SO2 ~ 측정일시,refactoring_Data,mean), | ||
37 | + aggregate(CO ~ 측정일시,refactoring_Data,mean), | ||
38 | + aggregate(O3 ~ 측정일시,refactoring_Data,mean), | ||
39 | + aggregate(NO2 ~ 측정일시,refactoring_Data,mean), | ||
40 | + aggregate(PM10 ~ 측정일시,refactoring_Data,mean) | ||
41 | + | ||
42 | + ) | ||
43 | + refactoring_Data<-refactoring_Data[-c(3,5,7,9)] | ||
44 | + | ||
45 | + LocationDataList[[j]]<-refactoring_Data | ||
46 | + | ||
47 | + }else{ | ||
48 | + | ||
49 | + refactoring_Data<-subset(temp_Data,지역==LocationNameList[j]) | ||
50 | + | ||
51 | + refactoring_Data[is.na(refactoring_Data)]<-0 #결측치 제거 | ||
52 | + | ||
53 | + refactoring_Data<-data.frame( #서로다른 측정소들의 측정값을 평균으로 통합 | ||
54 | + aggregate(SO2 ~ 측정일시,refactoring_Data,mean), | ||
55 | + aggregate(CO ~ 측정일시,refactoring_Data,mean), | ||
56 | + aggregate(O3 ~ 측정일시,refactoring_Data,mean), | ||
57 | + aggregate(NO2 ~ 측정일시,refactoring_Data,mean), | ||
58 | + aggregate(PM10 ~ 측정일시,refactoring_Data,mean) | ||
59 | + | ||
60 | + ) | ||
61 | + refactoring_Data<-refactoring_Data[-c(3,5,7,9)] | ||
62 | + | ||
63 | + rbind_data<-rbind(data.frame(LocationDataList[j]),refactoring_Data) | ||
64 | + | ||
65 | + LocationDataList[[j]]<-rbind_data | ||
66 | + | ||
67 | + } | ||
68 | + } | ||
69 | + | ||
70 | +} | ||
71 | + | ||
72 | + | ||
73 | +for(i in 1:LocationNameList_cnt){ | ||
74 | + | ||
75 | + write.csv(data.frame(LocationDataList[i]), | ||
76 | + paste(set_src_dir,"전체/",LocationNameList[i],".csv",sep = ""), | ||
77 | + sep = ",", | ||
78 | + row.names = FALSE, | ||
79 | + col.names = FALSE, | ||
80 | + quote = FALSE, | ||
81 | + append = FALSE) | ||
82 | + | ||
83 | +} | ||
84 | + |
3차전처리_연도별Code.R
0 → 100644
1 | + | ||
2 | + | ||
3 | +src_dir<-c("2010104050_박재호_졸업논문/데이터/대기오염데이터/2차전처리(지역별분할 및 곽측소 시별 통합 및 연도통합)/2016/") | ||
4 | +src_file<-list.files(src_dir) | ||
5 | +src_file_cnt<-length(src_file) | ||
6 | +#src_file_cnt | ||
7 | + | ||
8 | +temp <- read.csv(paste(src_dir, src_file[j], sep=""), stringsAsFactors = F) | ||
9 | + | ||
10 | + | ||
11 | +for(i in 1:3){ # 연도별 데이터 처리시 src_dir 과 substr 범위 수정 | ||
12 | + | ||
13 | + for(j in 1:src_file_cnt){ | ||
14 | + | ||
15 | + temp <- read.csv(paste(src_dir, src_file[j], sep=""), stringsAsFactors = F) | ||
16 | + if(i==2){ | ||
17 | + temp$측정일시<-substr(temp$측정일시,1,10) # Day | ||
18 | + } | ||
19 | + if(i==3){ | ||
20 | + temp$측정일시<-substr(temp$측정일시,1,7) # month | ||
21 | + } | ||
22 | + | ||
23 | + if(j==1){ | ||
24 | + | ||
25 | + refactoring_Data<-temp | ||
26 | + | ||
27 | + }else{ | ||
28 | + | ||
29 | + | ||
30 | + refactoring_Data<-rbind(refactoring_Data, temp) | ||
31 | + | ||
32 | + refactoring_Data<-data.frame( | ||
33 | + aggregate(SO2 ~ 측정일시,refactoring_Data,mean), | ||
34 | + aggregate(CO ~ 측정일시,refactoring_Data,mean), | ||
35 | + aggregate(O3 ~ 측정일시,refactoring_Data,mean), | ||
36 | + aggregate(NO2 ~ 측정일시,refactoring_Data,mean), | ||
37 | + aggregate(PM10 ~ 측정일시,refactoring_Data,mean) | ||
38 | + | ||
39 | + ) | ||
40 | + refactoring_Data<-refactoring_Data[-c(3,5,7,9)] | ||
41 | + | ||
42 | + } | ||
43 | + | ||
44 | + } | ||
45 | + | ||
46 | + if(i==1){ | ||
47 | + write.csv(refactoring_Data, "2010104050_박재호_졸업논문/데이터/대기오염데이터/3차전처리(경기도 전체)/2016/경기도2016_Hour.csv") | ||
48 | + } | ||
49 | + if(i==2){ | ||
50 | + write.csv(refactoring_Data, "2010104050_박재호_졸업논문/데이터/대기오염데이터/3차전처리(경기도 전체)/2016/경기도2016_Day.csv") | ||
51 | + } | ||
52 | + if(i==3){ | ||
53 | + write.csv(refactoring_Data, "2010104050_박재호_졸업논문/데이터/대기오염데이터/3차전처리(경기도 전체)/2016/경기도2016_month.csv") | ||
54 | + | ||
55 | + } | ||
56 | + | ||
57 | +} | ||
58 | + | ||
59 | + | ||
60 | + | ||
61 | + | ||
62 | + | ||
63 | + |
3차전처리_전체Code.R
0 → 100644
1 | + | ||
2 | + | ||
3 | +src_dir<-c("2010104050_박재호_졸업논문/데이터/대기오염데이터/2차전처리(지역별분할 및 곽측소 시별 통합 및 연도통합)/전체/") | ||
4 | +src_file<-list.files(src_dir) | ||
5 | +src_file_cnt<-length(src_file) | ||
6 | +#src_file_cnt | ||
7 | +set_src_dir<-c("2010104050_박재호_졸업논문/데이터/대기오염데이터/3차전처리(경기도 전체)/") | ||
8 | + | ||
9 | +for(i in 1:3){ # 연도별 데이터 처리시 src_dir 과 substr 범위 수정 | ||
10 | + | ||
11 | + for(j in 1:src_file_cnt){ | ||
12 | + | ||
13 | + temp <- read.csv(paste(src_dir, src_file[j], sep=""), stringsAsFactors = F) | ||
14 | + if(i==2){ | ||
15 | + temp$측정일시<-substr(temp$측정일시,1,5) # Day | ||
16 | + } | ||
17 | + if(i==3){ | ||
18 | + temp$측정일시<-substr(temp$측정일시,1,2) # month | ||
19 | + } | ||
20 | + | ||
21 | + if(j==1){ | ||
22 | + | ||
23 | + refactoring_Data<-temp | ||
24 | + | ||
25 | + }else{ | ||
26 | + | ||
27 | + | ||
28 | + refactoring_Data<-rbind(refactoring_Data, temp) | ||
29 | + | ||
30 | + refactoring_Data<-data.frame( | ||
31 | + aggregate(SO2 ~ 측정일시,refactoring_Data,mean), | ||
32 | + aggregate(CO ~ 측정일시,refactoring_Data,mean), | ||
33 | + aggregate(O3 ~ 측정일시,refactoring_Data,mean), | ||
34 | + aggregate(NO2 ~ 측정일시,refactoring_Data,mean), | ||
35 | + aggregate(PM10 ~ 측정일시,refactoring_Data,mean) | ||
36 | + | ||
37 | + ) | ||
38 | + refactoring_Data<-refactoring_Data[-c(3,5,7,9)] | ||
39 | + | ||
40 | + } | ||
41 | + | ||
42 | + } | ||
43 | + | ||
44 | + if(i==1){ | ||
45 | + write.csv(refactoring_Data, "2010104050_박재호_졸업논문/데이터/대기오염데이터/3차전처리(경기도 전체)/경기도전체_Hour.csv") | ||
46 | + } | ||
47 | + if(i==2){ | ||
48 | + write.csv(refactoring_Data, "2010104050_박재호_졸업논문/데이터/대기오염데이터/3차전처리(경기도 전체)/경기도전체_Day.csv") | ||
49 | + } | ||
50 | + if(i==3){ | ||
51 | + write.csv(refactoring_Data, "2010104050_박재호_졸업논문/데이터/대기오염데이터/3차전처리(경기도 전체)/경기도전체_month.csv") | ||
52 | + | ||
53 | + } | ||
54 | + | ||
55 | +} | ||
56 | + | ||
57 | + | ||
58 | + | ||
59 | + | ||
60 | + | ||
61 | + |
[박재호]머신러닝을 활용한 대기환경 빅데이터 분석 및 예측.docx
0 → 100644
No preview for this file type
대본.docx
0 → 100644
No preview for this file type
종관관측기상데이터_전처리.R
0 → 100644
1 | + | ||
2 | +src_dir<-c("2010104050_박재호_졸업논문/데이터/원자료/종관관측기상데이터/") | ||
3 | + | ||
4 | +src_file<-list.files(src_dir) | ||
5 | +#src_file | ||
6 | + | ||
7 | +src_file_cnt<-length(src_file) | ||
8 | +#src_file_cnt | ||
9 | + | ||
10 | + | ||
11 | +temp_Data<-read.csv(paste(src_dir, src_file[1], sep=""), header = F, stringsAsFactors = F) | ||
12 | + | ||
13 | +for(i in 1:src_file_cnt){ | ||
14 | + | ||
15 | + temp_Data<-read.csv(paste(src_dir, src_file[i], sep=""), header = F, stringsAsFactors = F) | ||
16 | + temp_Data<-temp_Data[-1,c(2:6)] | ||
17 | + colnames(temp_Data)<-c("측정일시","기온","강수량","풍속(m/s)","풍향(16방위)") | ||
18 | + | ||
19 | + | ||
20 | + temp_Data$측정일시 <- sub(pattern = " 0:",replacement = " 00:",x = temp_Data$측정일시) | ||
21 | + temp_Data$측정일시 <- sub(pattern = " 1:",replacement = " 01:",x = temp_Data$측정일시) | ||
22 | + temp_Data$측정일시 <- sub(pattern = " 2:",replacement = " 02:",x = temp_Data$측정일시) | ||
23 | + temp_Data$측정일시 <- sub(pattern = " 3:",replacement = " 03:",x = temp_Data$측정일시) | ||
24 | + temp_Data$측정일시 <- sub(pattern = " 4:",replacement = " 04:",x = temp_Data$측정일시) | ||
25 | + temp_Data$측정일시 <- sub(pattern = " 5:",replacement = " 05:",x = temp_Data$측정일시) | ||
26 | + temp_Data$측정일시 <- sub(pattern = " 6:",replacement = " 06:",x = temp_Data$측정일시) | ||
27 | + temp_Data$측정일시 <- sub(pattern = " 7:",replacement = " 07:",x = temp_Data$측정일시) | ||
28 | + temp_Data$측정일시 <- sub(pattern = " 8:",replacement = " 08:",x = temp_Data$측정일시) | ||
29 | + temp_Data$측정일시 <- sub(pattern = " 9:",replacement = " 09:",x = temp_Data$측정일시) | ||
30 | + | ||
31 | + temp_Data[is.na(temp_Data)]<-0 | ||
32 | + | ||
33 | + write.csv(temp_Data,paste("2010104050_박재호_졸업논문/데이터/종관관측기상데이터/AOS_",src_file[i])) | ||
34 | + | ||
35 | +} | ||
36 | + |
-
Please register or login to post a comment