SlideShare a Scribd company logo
GOSSEM
https://cafe.naver.com/gossemaction
• R
• R 환경
• R Studio
• R 기초
• R 기초 함수
• Types - 데이터타입
• Vector
• 조건문
• 반복문
 R was created by Ross Ihaka and Robert Gentleman at the University
of Auckland, New Zealand
 currently developed by the R Development Core Team.
 This programming language was named R, based on the first letter
of first name of the two R authors (Robert Gentleman and Ross Ihaka)
 R made its first appearance in 1993.
 Since mid-1997 there has been a core group (the "R Core Team")
who can modify the R source code archive.
 world’s most widely used statistics programming language
software environment for statistical analysis, graphics
representation and reporting.
 if your windows is 64-bit, then it installs both the 32-bit and 64-
bit versions.
 Download
 https://cloud.r-project.org/
programming language for statistical analysis, graphics
representation and reporting.
 Download R Studio
 https://www.rstudio.com/products/rstudio/download/#downlo
ad
 화면지우기
 Ctrl + L
 도움말보기
 ?명령어
 ?print
 R Studio
 주석
 한줄 주석
 #
- concat
- 값을 연결해서 출력
> num.1 = c(1,2,3)
> num.2 = c(4,5,6)
> print(class(num.1))
[1] "numeric"
> cat(num.1, num.2)
1 2 3 4 5 6
- 현재 워크스페이스의 변수목록을 리턴
> ls()
[1] "apple_colors" "BMI" "factor_apple"
[4] "num.1" "num.2" "sum.0"
> print(class(ls()))
[1] "character"
- 변수를 삭제함
> ls()
[1] "apple_colors" "BMI" "factor_apple"
[4] "num.1" "num.2" "sum.0"
> print(class(ls()))
[1] "character"
> rm(BMI)
> ls()
[1] "apple_colors" "factor_apple" "num.1"
[4] "num.2" "sum.0"
> rm(sum.0)
> ls()
[1] "apple_colors" "factor_apple" "num.1"
[4] "num.2"
> print(class(TRUE))
[1] "logical"
> print(class(FALSE))
[1] "logical"
• numeric
• 표기
• 수만입력
• 표현범위
• 제한 없음
> print(class(7))
[1] "numeric"
> print(class(7.7))
[1] "numeric"
> print(class(7777777777777777777777777777777))
[1] "numeric"
>
print(class(7777777777777777777777777777777777777777777777777777777
7777777777777777777777777777777777777777777777777777777777777777
77777777777777777777777777777777777777777777777))
[1] "numeric"
• Integer
• 표기
• 수L
• 정수 9자리까지만 표현 가능
> print(class(7L))
[1] "integer"
> print(class(77L))
[1] "integer"
> print(class(777L))
[1] "integer"
> print(class(7777L))
[1] "integer"
> print(class(77777L))
[1] "integer"
> print(class(777777L))
[1] "integer"
> print(class(7777777L))
[1] "integer"
> print(class(77777777L))
[1] "integer"
> print(class(777777777L))
[1] "integer"
> print(class(7777777777L))
[1] "numeric"
Warning message:
non-integer value 7777777777L qualified with L; using numeric value
> print(class('7'))
[1] "character"
> print(class("7"))
[1] "character"
> print(class("7.7"))
[1] "character"
> print(class("hong"))
[1] "character"
A vector is a sequence of data elements of the same basic type
1차원 배열
> print(c(1:7))
[1] 1 2 3 4 5 6 7
> print(c(3:-3))
[1] 3 2 1 0 -1 -2 -3
> seq(from=1, to=10, by=2)
[1] 1 3 5 7 9
> seq(1,10,2)
[1] 1 3 5 7 9
> seq(1, 3, by=0.3)
[1] 1.0 1.3 1.6 1.9 2.2 2.5 2.8
> is.vector(seq(1, 3, by=0.3))
[1] TRUE
> seq(1, 5, length=3)
[1] 1 3 5
> seq(1, 5, length=4)
[1] 1.000000 2.333333 3.666667 5.000000
> seq(1, 5, length=10)
[1] 1.000000 1.444444 1.888889 2.333333 2.777778
[6] 3.222222 3.666667 4.111111 4.555556 5.000000
> x <- 1:4
> print(x)
[1] 1 2 3 4
> #start
> c(1,3:5)
[1] 1 3 4 5
> c(1:10,20.5, "start")
[1] "1" "2" "3" "4" "5" "6" "7" "8" "9"
"10" "20.5" "start“
> x = c(1,2,3)
> x+1
[1] 2 3 4
charactor vector를 키로 사용가능
> x <- c('tom'='tom is a good boy', 'john'='john is a kind bo
dy')
> x['tom']
tom
"tom is a good boy"
> x['john']
john
"john is a kind body"
> rep(c(1,2,3), each=2, times=3)
[1] 1 1 2 2 3 3 1 1 2 2 3 3 1 1 2 2
[17] 3 3
> g <- seq(0, 10, 2)
> g
[1] 0 2 4 6 8 10
> g[1]
[1] 0
> g[c(2,4)]
[1] 2 6
> g[-1]
[1] 2 4 6 8 10
> g[1.1]
[1] 0
> g[2.9]
[1] 2
> g <- seq(0, 10, 2)
> g[c(TRUE, FALSE, TRUE, FALSE, TRUE, FALSE)]
[1] 0 4 8
> g[ g > 4]
[1] 6 8 10
 벡터를 팩터화
◦ 벡터에 levels 라는 키가 추가되어 팩터가 됨.
> # Apply the factor function.
> factor_data <- factor(data)
>
> print(factor_data)
[1] East West East North North East West West We
st
[10] East North
Levels: East North West
 팩터인지 아닌지 확인
> # Create a vector as input.
> data <- c("East","West","East","North","North","East","We
st","West","West","East","North")
>
> print(data)
[1] "East" "West" "East" "North" "North" "East" "West"
[8] "West" "West" "East" "North"
> print(is.factor(data))
[1] FALSE
펙터에서 LEVEL만 추출해서 벡터로 리턴
> data <- c("East","West","East","North","North","East",
"West","West","West","East","North")
> factor_data <- factor(data)
> levels(factor_data)
[1] "East" "North" "West"
 레벨값을 복사해서 벡터 생성
> v <- gl(3, 4, labels = c("Tampa", "Seattle","Boston"))
> print(v)
[1] Tampa Tampa Tampa Tampa Seattle Seattle
Seattle
[8] Seattle Boston Boston Boston Boston
Levels: Tampa Seattle Boston
x <- 5
if(x > 0){
print("Positive number")
}
> x <- -5
> y <- if(x > 0) 5 else 6
> y
[1] 6
x <- c(2,5,3,9,8,11,6)
count <- 0
for (val in x) {
if(val %% 2 == 0) count = count+1
}
print(count)
i <- 1
while (i < 6) {
print(i)
i = i+1
}
x <- 1:5
for (val in x) {
if (val == 3){
break
}
print(val)
}
[1] 1
[1] 2
x <- 1:5
for (val in x) {
if (val == 3){
next
}
print(val)
}
[1] 1
[1] 2
[1] 4
[1] 5

More Related Content

Similar to R v01 rprogamming_basic01 (R 프로그래밍 기본)

Programming with R in Big Data Analytics
Programming with R in Big Data AnalyticsProgramming with R in Big Data Analytics
Programming with R in Big Data Analytics
Archana Gopinath
 
RDataMining slides-r-programming
RDataMining slides-r-programmingRDataMining slides-r-programming
RDataMining slides-r-programming
Yanchang Zhao
 
2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors
krishna singh
 
R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011
Mandi Walls
 
R Programming: Export/Output Data In R
R Programming: Export/Output Data In RR Programming: Export/Output Data In R
R Programming: Export/Output Data In R
Rsquared Academy
 
Ggplot2 v3
Ggplot2 v3Ggplot2 v3
Ggplot2 v3
Josh Doyle
 
R Programming - part 1.pdf
R Programming - part 1.pdfR Programming - part 1.pdf
R Programming - part 1.pdf
RohanBorgalli
 
R is a very flexible and powerful programming language, as well as a.pdf
R is a very flexible and powerful programming language, as well as a.pdfR is a very flexible and powerful programming language, as well as a.pdf
R is a very flexible and powerful programming language, as well as a.pdf
annikasarees
 
Unit 1 - R Programming (Part 2).pptx
Unit 1 - R Programming (Part 2).pptxUnit 1 - R Programming (Part 2).pptx
Unit 1 - R Programming (Part 2).pptx
Malla Reddy University
 
R Language
R LanguageR Language
R Language
ShwetDadhaniya1
 
[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2
Kevin Chun-Hsien Hsu
 
R basics
R basicsR basics
R basics
Sagun Baijal
 
2015-10-23_wim_davis_r_slides.pptx on consumer
2015-10-23_wim_davis_r_slides.pptx on consumer2015-10-23_wim_davis_r_slides.pptx on consumer
2015-10-23_wim_davis_r_slides.pptx on consumer
tirlukachaitanya
 
BA lab1.pptx
BA lab1.pptxBA lab1.pptx
BA lab1.pptx
sherifsalem24
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
Sander Kieft
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
Stuart Roebuck
 
第二讲 预备-Python基礎
第二讲 预备-Python基礎第二讲 预备-Python基礎
第二讲 预备-Python基礎
anzhong70
 
第二讲 Python基礎
第二讲 Python基礎第二讲 Python基礎
第二讲 Python基礎
juzihua1102
 
Microsoft NERD Talk - R and Tableau - 2-4-2013
Microsoft NERD Talk - R and Tableau - 2-4-2013Microsoft NERD Talk - R and Tableau - 2-4-2013
Microsoft NERD Talk - R and Tableau - 2-4-2013
Tanya Cashorali
 

Similar to R v01 rprogamming_basic01 (R 프로그래밍 기본) (20)

Programming with R in Big Data Analytics
Programming with R in Big Data AnalyticsProgramming with R in Big Data Analytics
Programming with R in Big Data Analytics
 
Python lecture 05
Python lecture 05Python lecture 05
Python lecture 05
 
RDataMining slides-r-programming
RDataMining slides-r-programmingRDataMining slides-r-programming
RDataMining slides-r-programming
 
2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors
 
R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011R for Pirates. ESCCONF October 27, 2011
R for Pirates. ESCCONF October 27, 2011
 
R Programming: Export/Output Data In R
R Programming: Export/Output Data In RR Programming: Export/Output Data In R
R Programming: Export/Output Data In R
 
Ggplot2 v3
Ggplot2 v3Ggplot2 v3
Ggplot2 v3
 
R Programming - part 1.pdf
R Programming - part 1.pdfR Programming - part 1.pdf
R Programming - part 1.pdf
 
R is a very flexible and powerful programming language, as well as a.pdf
R is a very flexible and powerful programming language, as well as a.pdfR is a very flexible and powerful programming language, as well as a.pdf
R is a very flexible and powerful programming language, as well as a.pdf
 
Unit 1 - R Programming (Part 2).pptx
Unit 1 - R Programming (Part 2).pptxUnit 1 - R Programming (Part 2).pptx
Unit 1 - R Programming (Part 2).pptx
 
R Language
R LanguageR Language
R Language
 
[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2[1062BPY12001] Data analysis with R / week 2
[1062BPY12001] Data analysis with R / week 2
 
R basics
R basicsR basics
R basics
 
2015-10-23_wim_davis_r_slides.pptx on consumer
2015-10-23_wim_davis_r_slides.pptx on consumer2015-10-23_wim_davis_r_slides.pptx on consumer
2015-10-23_wim_davis_r_slides.pptx on consumer
 
BA lab1.pptx
BA lab1.pptxBA lab1.pptx
BA lab1.pptx
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
第二讲 预备-Python基礎
第二讲 预备-Python基礎第二讲 预备-Python基礎
第二讲 预备-Python基礎
 
第二讲 Python基礎
第二讲 Python基礎第二讲 Python基礎
第二讲 Python基礎
 
Microsoft NERD Talk - R and Tableau - 2-4-2013
Microsoft NERD Talk - R and Tableau - 2-4-2013Microsoft NERD Talk - R and Tableau - 2-4-2013
Microsoft NERD Talk - R and Tableau - 2-4-2013
 

Recently uploaded

Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Natan Silnitsky
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 

Recently uploaded (20)

Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 

R v01 rprogamming_basic01 (R 프로그래밍 기본)

  • 2. • R • R 환경 • R Studio • R 기초 • R 기초 함수 • Types - 데이터타입 • Vector • 조건문 • 반복문
  • 3.  R was created by Ross Ihaka and Robert Gentleman at the University of Auckland, New Zealand  currently developed by the R Development Core Team.  This programming language was named R, based on the first letter of first name of the two R authors (Robert Gentleman and Ross Ihaka)  R made its first appearance in 1993.  Since mid-1997 there has been a core group (the "R Core Team") who can modify the R source code archive.  world’s most widely used statistics programming language
  • 4. software environment for statistical analysis, graphics representation and reporting.  if your windows is 64-bit, then it installs both the 32-bit and 64- bit versions.  Download  https://cloud.r-project.org/
  • 5. programming language for statistical analysis, graphics representation and reporting.  Download R Studio  https://www.rstudio.com/products/rstudio/download/#downlo ad
  • 6.  화면지우기  Ctrl + L  도움말보기  ?명령어  ?print
  • 7.  R Studio  주석  한줄 주석  #
  • 8. - concat - 값을 연결해서 출력 > num.1 = c(1,2,3) > num.2 = c(4,5,6) > print(class(num.1)) [1] "numeric" > cat(num.1, num.2) 1 2 3 4 5 6
  • 9. - 현재 워크스페이스의 변수목록을 리턴 > ls() [1] "apple_colors" "BMI" "factor_apple" [4] "num.1" "num.2" "sum.0" > print(class(ls())) [1] "character"
  • 10. - 변수를 삭제함 > ls() [1] "apple_colors" "BMI" "factor_apple" [4] "num.1" "num.2" "sum.0" > print(class(ls())) [1] "character" > rm(BMI) > ls() [1] "apple_colors" "factor_apple" "num.1" [4] "num.2" "sum.0" > rm(sum.0) > ls() [1] "apple_colors" "factor_apple" "num.1" [4] "num.2"
  • 11. > print(class(TRUE)) [1] "logical" > print(class(FALSE)) [1] "logical"
  • 12. • numeric • 표기 • 수만입력 • 표현범위 • 제한 없음 > print(class(7)) [1] "numeric" > print(class(7.7)) [1] "numeric" > print(class(7777777777777777777777777777777)) [1] "numeric" > print(class(7777777777777777777777777777777777777777777777777777777 7777777777777777777777777777777777777777777777777777777777777777 77777777777777777777777777777777777777777777777)) [1] "numeric"
  • 13. • Integer • 표기 • 수L • 정수 9자리까지만 표현 가능 > print(class(7L)) [1] "integer" > print(class(77L)) [1] "integer" > print(class(777L)) [1] "integer" > print(class(7777L)) [1] "integer" > print(class(77777L)) [1] "integer" > print(class(777777L)) [1] "integer" > print(class(7777777L)) [1] "integer" > print(class(77777777L)) [1] "integer" > print(class(777777777L)) [1] "integer" > print(class(7777777777L)) [1] "numeric" Warning message: non-integer value 7777777777L qualified with L; using numeric value
  • 14. > print(class('7')) [1] "character" > print(class("7")) [1] "character" > print(class("7.7")) [1] "character" > print(class("hong")) [1] "character"
  • 15. A vector is a sequence of data elements of the same basic type 1차원 배열
  • 16. > print(c(1:7)) [1] 1 2 3 4 5 6 7 > print(c(3:-3)) [1] 3 2 1 0 -1 -2 -3
  • 17. > seq(from=1, to=10, by=2) [1] 1 3 5 7 9 > seq(1,10,2) [1] 1 3 5 7 9 > seq(1, 3, by=0.3) [1] 1.0 1.3 1.6 1.9 2.2 2.5 2.8 > is.vector(seq(1, 3, by=0.3)) [1] TRUE > seq(1, 5, length=3) [1] 1 3 5 > seq(1, 5, length=4) [1] 1.000000 2.333333 3.666667 5.000000 > seq(1, 5, length=10) [1] 1.000000 1.444444 1.888889 2.333333 2.777778 [6] 3.222222 3.666667 4.111111 4.555556 5.000000
  • 18. > x <- 1:4 > print(x) [1] 1 2 3 4 > #start > c(1,3:5) [1] 1 3 4 5 > c(1:10,20.5, "start") [1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "20.5" "start“ > x = c(1,2,3) > x+1 [1] 2 3 4
  • 19. charactor vector를 키로 사용가능 > x <- c('tom'='tom is a good boy', 'john'='john is a kind bo dy') > x['tom'] tom "tom is a good boy" > x['john'] john "john is a kind body"
  • 20. > rep(c(1,2,3), each=2, times=3) [1] 1 1 2 2 3 3 1 1 2 2 3 3 1 1 2 2 [17] 3 3
  • 21. > g <- seq(0, 10, 2) > g [1] 0 2 4 6 8 10 > g[1] [1] 0 > g[c(2,4)] [1] 2 6 > g[-1] [1] 2 4 6 8 10 > g[1.1] [1] 0 > g[2.9] [1] 2
  • 22. > g <- seq(0, 10, 2) > g[c(TRUE, FALSE, TRUE, FALSE, TRUE, FALSE)] [1] 0 4 8 > g[ g > 4] [1] 6 8 10
  • 23.  벡터를 팩터화 ◦ 벡터에 levels 라는 키가 추가되어 팩터가 됨. > # Apply the factor function. > factor_data <- factor(data) > > print(factor_data) [1] East West East North North East West West We st [10] East North Levels: East North West
  • 24.  팩터인지 아닌지 확인 > # Create a vector as input. > data <- c("East","West","East","North","North","East","We st","West","West","East","North") > > print(data) [1] "East" "West" "East" "North" "North" "East" "West" [8] "West" "West" "East" "North" > print(is.factor(data)) [1] FALSE
  • 25. 펙터에서 LEVEL만 추출해서 벡터로 리턴 > data <- c("East","West","East","North","North","East", "West","West","West","East","North") > factor_data <- factor(data) > levels(factor_data) [1] "East" "North" "West"
  • 26.  레벨값을 복사해서 벡터 생성 > v <- gl(3, 4, labels = c("Tampa", "Seattle","Boston")) > print(v) [1] Tampa Tampa Tampa Tampa Seattle Seattle Seattle [8] Seattle Boston Boston Boston Boston Levels: Tampa Seattle Boston
  • 27. x <- 5 if(x > 0){ print("Positive number") }
  • 28. > x <- -5 > y <- if(x > 0) 5 else 6 > y [1] 6
  • 29. x <- c(2,5,3,9,8,11,6) count <- 0 for (val in x) { if(val %% 2 == 0) count = count+1 } print(count)
  • 30. i <- 1 while (i < 6) { print(i) i = i+1 }
  • 31. x <- 1:5 for (val in x) { if (val == 3){ break } print(val) } [1] 1 [1] 2
  • 32. x <- 1:5 for (val in x) { if (val == 3){ next } print(val) } [1] 1 [1] 2 [1] 4 [1] 5