Rstudio(2) 데이터 저장 및 수집

hyukstory 혁스토리·2020년 8월 22일
0

Rstudio

목록 보기
3/16

< 2 > 데이터 저장 및 수집

2-1) 데이터 저장하기

name <- c('john', 'jaehee', 'juliet', 'james')
sex <- c('f', 'f', 'f', 'm')
occup <- c('althele', 'doctor', 'ceo', 'analyst')
age <- c(40, 35, 43, 29)
member <- data.frame(name, age, sex, occup)
member
member[1,3] <- 'm' # raw 데이터 작성

write.csv(변수, file="위치/파일명")

write.csv(member,file="c:/Temp/Rstudy/data/member.csv")  

2-2) 데이터 불러오기

read.csv(file="위치/파일명")

member.csv <- read.csv("C:/TEMP/Rstudy/data/member.csv")

read_excel : 엑셀 파일 불러오기

read_excel(경로, sheet = , range = , col_names = T or F)

install.packages("readxl")
library(readxl)
excel_data_ex <- read_excel("C:/TEMP/Rstudy/data/data_ex.xls") 
View(excel_data_ex)

read.table : 테이블 형태로 된 파일 불러오기

탭으로 구분된 TXT 파일인 경우 : read.table(경로, header = T)

쉼표로 구분된 TXT 파일인 경우 : read.table(경로, header = T, sep = ",")

변수명 추가하여 가져오기 : read.table(경로, header = T, sep = ",", col.names = Varname)

ex_data <- read.table("c:/TEMP/Rstudy/data/data_ex.txt", header = T) #필드명이 셀값으로 내려왔을때 header = T
View(ex_data)

save(변수, file="위치/파일명")

load(file="위치/파일명")

View

profile
문돌이의 고군분투 개발 공부

0개의 댓글