읽기 readingit4lnu.hannam.ac.kr/stat_notes/softwares/about_r/data_r... · 2018-05-02 · 읽기...

3
읽기 reading 3 1. txt 데이터 : read.table() 함수 iris<-read.table('http://wolfpack.hnu.ac.kr/Stat_Notes/adv_stat/data/iris.txt',header=T ) dim(iris);names(iris) read.table() 이용하여 얻은 데이터는 데이터 포멧(data.frame) 오브젝트로 iris에 저장된다. dim() 함수 : 데이터 형식 오브젝트의 차수 출력 - 행 150(관측치 개수, 열=5개 변수 개수임 dim(iris)[1]은 150을 의미한다. names() : 데이터 오브젝트인 경우 차수를 출력해 준다. 2. CSV 포멧 : 가장 선호되는 데이터 포멧 read.csv() us_crime<-read.csv('http://wolfpack.hnu.ac.kr/Stat_Notes/example_data/US_crime.csv' , header=T) names(us_crime);dim(us_crime) #읽어 들인 외부 데이터 변수명, 데이터 차원 출력 (변수 개수=12, 관측치 n=5,359) 12

Upload: others

Post on 02-Jun-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 읽기 readingit4lnu.hannam.ac.kr/Stat_Notes/softwares/about_R/data_R... · 2018-05-02 · 읽기 reading 3 1.txt 데이터 : read.table() 함수 iris

읽기 reading

3

1. txt 데이터 : read.table() 함수

iris<-read.table('http://wolfpack.hnu.ac.kr/Stat_Notes/adv_stat/data/iris.txt',header=T)dim(iris);names(iris)

•read.table() 이용하여 얻은 데이터는 데이터 포멧(data.frame) 오브젝트로 iris에 저장된다.

•dim() 함수 : 데이터 형식 오브젝트의 차수 출력 - 행 150(관측치 개수, 열=5개 변수 개수임

•dim(iris)[1]은 150을 의미한다.

•names() : 데이터 오브젝트인 경우 차수를 출력해 준다.

2.CSV 포멧 : 가장 선호되는 데이터 포멧 read.csv()

us_crime<-read.csv('http://wolfpack.hnu.ac.kr/Stat_Notes/example_data/US_crime.csv', header=T)names(us_crime);dim(us_crime) #읽어 들인 외부 데이터 변수명, 데이터 차원 출력

(변수 개수=12, 관측치 n=5,359)

12

Page 2: 읽기 readingit4lnu.hannam.ac.kr/Stat_Notes/softwares/about_R/data_R... · 2018-05-02 · 읽기 reading 3 1.txt 데이터 : read.table() 함수 iris

3.xls 데이터

install.packages('gdata'); library(gdata)mri_iq<-read.xls('http://wolfpack.hnu.ac.kr/lecture/Spring07/REG/mri_iq.xls', sheet=1, header=T)dim(mri_iq); names(mri_iq)

4.SAS data

install.packages('sas7bdat')library(sas7bdat)baseball<-read.sas7bdat('http://wolfpack.hnu.ac.kr/Spring2018/baseball.sas7bdat')names(baseball);dim(baseball)

5. built in 데이터 사용하기

data()

아래와 같이 내장된 데이터 리스트가 출력된다.

13

Page 3: 읽기 readingit4lnu.hannam.ac.kr/Stat_Notes/softwares/about_R/data_R... · 2018-05-02 · 읽기 reading 3 1.txt 데이터 : read.table() 함수 iris

활용

names(ChickWeight)names(AirPassengers)head(ChickWeight,3) #데이터 첫 3개 행 관측값 출력

14

ChikWeight - 데이터 오브젝트AirPassengers - 시계열 데이터이므로 일반 데이터로 사용하려면 ds<-data.frame(AirPassengers) 오브젝트 타입을 바꾸어야 한다