데이터 분석/R
[R] 외부 데이터 불러오기
eunki
2021. 6. 19. 18:50
728x90
1. 엑셀 파일 불러오기
이때, Working directory에 불러올 파일이 있어야 한다.
read_excel("파일명", sheet, col_names)
col_names : 첫번째 행을 변수명으로 로드할지(True), 안할지(False)
install.packages("readxl") # readxl 패키지 설치
library("readxl") # readxl 패키지 로드
df_finalexam <- read_excel("finalexam.xlsx", sheet = 1, col_names = T)
df_finalexam
2. csv 파일 불러오기
csv 파일은 범용 데이터 형식으로, 값 사이를 쉼표(,)로 구분한다.
용량이 작아서 다양한 소프트웨어에서 사용된다.
read.csv("파일명", header)
header : 첫번째 행을 변수명으로 로드할지(True), 안할지(False)
# csv 파일 불러오기
read.csv("csv_exam.csv", header = T)
# csv 파일로 저장하기
write.csv(df_finalexam, file = "output_newdata.csv")
728x90