본문 바로가기

2018/05

(9)
데이터 가공 - 전처리 # 데이터 가공 - 전처리 # 조건에 맞는 데이터만 추출하기 library(dplyr) exam <- read.csv("d:/easy_r/sample_data/score.csv", stringsAsFactors = F) exam # exam에서 1학년만 추출, ==, !=, &(and), |(or) exam %>% filter(학년!=1) # 영어 점수 50점 이상 추출 exam %>% filter(영어 >= 50) # 이름 추출 exam %>% filter(이름 == '홍..
파생변수 만들기 # 파생변수 만들기 # 변수 조합해 파생변수 만들기 # 테스트 생성 df_raw <- data.frame(var1=c(1,2,1),var2=c(2,3,2)) df_raw # 파생변수 만들기 df_new <- df_raw df_new$var3 <- df_new$var1 + df_new$var2 df_new df_new$var3 <- (df_new$var1 + df_new$var2)/2 df_new mean(df_new$var3) # 조건문을 활용해 파생변수 만들기 mpg$total <- ..
변수명(컬럼) 바꾸기 # 변수명 바꾸기 install.packages("dplyr") library(dplyr) # 테스트 생성 df_raw <- data.frame(var1=c(1,2,1),var2=c(2,3,2)) df_raw # 복사본 만들기 df_new <- df_raw df_new # 변수명 바꾸기 df_new <- rename(df_new, new_var=var1) df_new df_raw # ggplot mpg test df_raw2 <- as.data.frame(ggplot2::mpg) df_new2 <- df_raw2 df_new2 <- rename(df_new2..
데이터 분석 기본 함수 #데이터 분석 df_csv_exam <- read.csv("d:/easy_r/sample_data/score.csv", stringsAsFactors = F) # 데이터 앞부분 확인 head(df_csv_exam) # 기본 6행 까지 출력 head(df_csv_exam, 10) # 10행 까지 출력 # 데이터 뒷부분 확인 tail(df_csv_exam) # 뒤에서 6행 까지 출력 tail(df_csv_exam, 10) # 뒤에서 10행 까지 출력 # 뷰어창에 데이터 ..
우분투 Postgresql 설치 # 우분투 16.04 postgresql 설치 # 설치 sudo apt-get install postgresql 비밀번호 > Y # 설치확인 dpkg -l | grep postgres # 관리자계정 확인 cat /etc/passwd | grep postgres # 상택확인 /etc/init.d/postgresql status # 관리자 계정 비밀번호 변경 sudo -u postgres psql template1 ALTER USER postgres with encrypted password 'xxxxxxxx'; # 접속확인..
RData 파일 저장 불러오기 # RData 파일 활용 # CSV 파일 불러오기 df_csv_exam <- read.csv("d:/easy_r/sample_data/score.csv", stringsAsFactors = F) df_csv_exam # RData 파일로 저장 save(df_csv_exam, file="d:/easy_r/sample_data/score.rda") # 데이터 프레임 삭제 rm(df_csv_exam) df_csv_exam # RData 불러오기 load("d:/easy_r/sample_data/score.rda") df_csv_exam
외부데이터 이용하기 - CSV # CSV 파일 불러오기 # header = F # 헤더가 없음 # stringsAsFactors = F # 변수를 factor 타입이 아닌 문자 타입으로 불러와 오류가 없음 df_csv_exam <- read.csv("d:/easy_r/sample_data/score.csv", stringsAsFactors = F) df_csv_exam # rm(df_csv_exam) # df_csv_exam
외부데이터 이용하기 - 엑셀 # 외부데이터 이용하기 - 엑셀 install.packages("readxl") library(readxl) # 엑셀불러오기 # df_exam <- read_excel("d:/easy_r/sample_data/score.xlsx", col_names=F) # 헤더 정보가 없을 경우 사용 # df_exam <- read_excel("d:/easy_r/sample_data/score.xlsx", sheet=1) # sheet 지정 하여 사용 df_exam <- read_excel("d:/easy_r/sample_data/score.xlsx..