1. R 프로그램 시작하기

R 프로그래밍 기초

 

 

Hello World 출력

 
 
 
 
 
 
print("Hello World!")
 
 
 
[1] "Hello World!"
 

 

 


 

패키지 사용.

  • randomForest를 로드해서 사용해 봅시다.
 
 
 
 
 
 
install.packages("randomForest") # ""안에 넣어야한다.
 
 
 
Installing package into 'C:/Users/KIIXXI/Documents/R/win-library/3.6'
(as 'lib' is unspecified)
 
package 'randomForest' successfully unpacked and MD5 sums checked

The downloaded binary packages are in
	C:\Users\KIIXXI\AppData\Local\Temp\RtmpIXIOTT\downloaded_packages
 
 
 
 
 
 
library(randomForest)  # library로 로드한다.
 
 
 
 

 

 


 

대입과 할당.

  • 변수 <- 수치나 계산식
 
 
 
 
 
 
2+3
x<-2
y<-3
x+y
 
 
 
5
 
5
 

 

 


 

변수 작성 규칙

  • 변수명의 대소문자 구분 및 확인 ex) KIM과 Kim은 다른 변수 이다.
  • 변수명의 시작이 숫자는 불가능.
  • 변수끼리 연산 가능.
  • 변수에 값을 다시 대입 가능 . (업데이트 개념)
 
 
 
 
 
 
3A <- 1 # 오류
 
 
 
Error in parse(text = x, srcfile = src): <text>:1:2: 예상하지 못한 기호(symbol)입니다.
1: 3A
     ^
Traceback:


 
 
 
 
 
 
A3 <- 1
x+y     # 변수끼리 연산 가능
 
 
 
5
 

 

 


 

R 함수

  • 특정 기능을 달성하는 명령어
 
 
 
 
 
 
sum <- function(x,y){
    return(x+y)
}
sum(2,5)
 
 
 
7
 

 

 


 

R 데이터 유형

  • 실수(numeric)
  • 정수(integer)
  • 인자(Factor) -> 만족,불만족
  • 논리값(Logical)
  • 문자열(character)
  • class 함수를 통하여 데이터 유형을 파악가능하다.
 
 
 
 
 
 
x<-8
class(x)
y<-"kim"
class(y)
z<-factor(c("T","F","TF"))
class(z)
w<-as.logical(c(1,0,1,0))
w
 
 
 
'numeric'
 
'character'
 
'factor'
 
  1. TRUE
  2. FALSE
  3. TRUE
  4. FALSE

 

댓글

Designed by JB FACTORY