- R
- 소개 http://www.rproject.org/
- 1976년 벨 연구소에서 S language 등장(John Chambers)
- 1993년 오클랜드 대학교에서 R language 개발(Ross Ihaka, Robert Gentleman) 오픈소스 프로그래밍 언어, 공짜
- 현재 가장 많은 통계학자와 분석가가 사용, 5000개 이상의 package 등록
- R은 만든 사람 이름이 R로 시작해서... 어이가 없다
- SAS보다 많이 씀. 가장 많은 통계학자와 분석가가 사용 중
- 14년 기준 Package가 5,000개가 넘는다. (Dataset과 Function의 모음이 Package가 됨) R의 경쟁력 원천임
- R도 Language인것은 맞음. Interpreter계열로 실행 속도는 느리지만 작업 속도는 더 빠름 (대화식.)
- R Studio는 지원 Tool로서 R자체를 직접 실행시킬 일이 없음
- Shiny Web Application: Data Visualization
- 존재하는 모든 것은 object 이며 모든 동사는 function call
- Vector는 여러개의 값으로 이루어진 하나의 object
- '사번 - 이름 - 성별 - 나이'는 하나의 Vector로서 4개의 원소를 갖는다
- 행 Vector와 열 Vector이 있음
-
type of object
“To understand computations in R, two slogans are helpful:
● Everything that exists is an object.
● Everything that happens is a function call.”
— John Chambers
object type을 따지는 이유는 type에 따라서 쓸 수 있는 function이 다르기 때문.
‘a’ + ‘b vs. ’1+2
- atomic vector
가장 기본이 되는 object type
데이터 분석에서 vector는 연산의 기본 단위.
1:10
c(1,2,3,4,5,6,7,8,9,10) #concatenate is.vector(1:10)
length(1:10)
중요!: 하나의 벡터는 오직 하나의 데이터 타입(type of data)만 저장할 수 있다.
- type of object
- 하나의 벡터는 오직 하나의 데이터 타입(type of data)만 저장할 수 있다.
-
types of data
6가지: double, integer, character, logical, complex, raw
factor
범주형 자료(categorical data): 성별, 학점 등
# check working directory
getwd()
# print object
print(1)
print(x)
# Arithmetic Operators
+10
-7
1 + 1
10 - 3
7 * 6
4 / 7
2^3
8 %% 2
8 %/% 2
8
# object
'a'
a
# assignment
a <- 1
a + 1
rm(a) # remove
ls() # lits objects
# element-wise execution
v10 <- 1:10 # assign number
v10 + 1 # increase each cell
v10 / 2 # divide each cell
v10 * 2
v10 + v10
v10 * v10
v10^2
# vector recycling
v2 <- 1:2
v10 + v2 # add 1,2 repeatedly
rep(v2, 5) # repeat v2 5times
v10 <- rep(v2,5)
v10
v3 <- 1:3 # assign 1,2,3
v10 + v3 # error
rep(v3, 4)[1:10] # limit to 10
rep(v3, 4) # up to 12
R 시작을 위한 기본 지식
'Fast Camp_DA' 카테고리의 다른 글
Fast Campus: Data Analytics 5일차 (3/11) Part I (0) | 2015.03.11 |
---|---|
Fast Campus: Data Analytics 4일차 (3/8) (0) | 2015.03.08 |
Fast Campus: Data Analytics 3일차 (3/4) Part II (0) | 2015.03.08 |
Fast Campus: Data Analytics 2일차 (3/1) (0) | 2015.03.01 |
Fast Camp: Data Analytics 수업 1일차 (2/25) (0) | 2015.02.25 |