SlideShare a Scribd company logo
R Language

   note
Data analysis and graphics with R
• R is a language and environment for statistical
  computing and graphics, similar to the S
  language originally developed at Bell Labs
Common commands
•   getwd() 读工作目录.
•   setwd(“c:/”) 改变工作目录
•   ls() 显示当前workspace的变量
•   rm(objectlist) Remove (delete) one or more objects.
•   options() View or set current options.
•   savehistory("myfile") Save the commands history to myfile ( default =
•   .Rhistory).
•   loadhistory("myfile") Reload a command's history (default = .Rhistory).
•   save.image("myfile") Save the workspace to myfile (default = .RData).
•   save(objectlist,file="myfile") Save specific objects to a file.
•   load("myfile") Load a workspace into the current session (default =
•   .RData).
R Data Structures
•
Vector
• Vector
  –   c (2,3,1,6,5,2)
  – X = c (1:9)
  – X*2 向量乘
      • 2,4,6,8,10,12,14,16,18
Array
• array(c(1:9), dim=c(3,3))
  –    [,1] [,2] [,3]
  –   [1,] 1 4 7
  –   [2,] 2 5 8
  –   [3,] 3 6 9
Matrix
myymatrix <- matrix(
     vector,
     nrow=number_of_rows,
     ncol=number_of_columns,
     byrow=logical_value,
     dimnames=list(
         char_vector_rownames,
         char_vector_colnames
     )
)
M = matrix(c(1:10), nrow=2, ncol=5, byrow=T)
                                 byrow=T横向填充                byrow=F竖向填充
                                 [,1] [,2] [,3] [,4] [,5]   [,1] [,2] [,3] [,4] [,5]
                                 [1,] 1 2 3 4 5             [1,] 1 3 5 7 9
                                 [2,] 6 7 8 9 10            [2,] 2 4 6 8 10
Matrix
a=matrix(c(1:10), nrow=2, ncol=5, byrow=T,
dimnames=list(c('R1','R2'),c('a','b','c','d','e')))
                         abcd e
                        R1 1 2 3 4 5
                        R2 6 7 8 9 10

• 选择数据:
    – a[1,2] 结果:2
    – a[2,c(3:5)] 结果:8,9,10
Array
• n1=c('r1','r2')
• n2=c('col1','col2','col3')
• n3=c('p1','p2','p3','p4')
•array(c(1:24),c(2,3,4),dimnames=list(n1,n2,n3)
 )
三维 数组
data frame
•   name=c('jack','tom','joe','linda')
•   age=c('21','23','20','19')
•   city=c('bj','sh','sh','bj')
•   d = data.frame(name,age,city)
•   Query:
    –   d['age']
    –   d[c('age','city')]
    –   d[1:2]
    –   d$age
• Edit:
    – d = edit(d)
data frame
• table(d$city,d$name)
  – jack joe linda tom
  – bj 1 0 1 0
  – sh 0 1 0 1


    attach(d)            with(d,{
    summary(name)        summary(name)
    …                    …
    detach(d)            })
Lists
• Lists are the most complex of the R data types

•   g <- "My First List"
•   h <- c(25, 26, 18, 39)
•   j <- matrix(1:10, nrow=5)
•   k <- c("one", "two", "three")
•   mylist <- list(title=g, ages=h, j, k)
data input
•
data input
• mydata <-
  data.frame(age=numeric(0),       gender=char
  acter(0), weight=numeric(0))
  mydata <- edit(mydata)

• mydataframe =
  read.table("c:/a.txt", header=FALSE, sep="t",
  row.names="name")
  – header:是否把第一行作为column name
  – row.names:标识
data input
• read excel:
  –   library(RODBC)
  –   channel <- odbcConnectExcel("c:/t.xlsx")
  –   mydataframe <- sqlFetch(channel, "Sheet1")
  –   odbcClose(channel)

• excel2007:
  – library(xlsx)
  – workbook <- "c:/myworkbook.xlsx"
  – mydataframe <- read.xlsx(workbook, 1)
data input
• library(RODBC)
• myconn <-odbcConnect("mydsn", uid="Rob",
  pwd="aardvark")
• crimedat <- sqlFetch(myconn, Crime)
• pundat <- sqlQuery(myconn, "select * from
  Punishment")
• close(myconn)
data export
•   png(), jpeg(),
•   bmp(), tiff(), xfig()
•   pdf("mygraph.pdf")
•   …….
•   dev.off()

More Related Content

What's hot

CLUSTERGRAM
CLUSTERGRAMCLUSTERGRAM
CLUSTERGRAM
Dr. Volkan OBAN
 
peRm R group. Review of packages for r for market data downloading and analysis
peRm R group. Review of packages for r for market data downloading and analysispeRm R group. Review of packages for r for market data downloading and analysis
peRm R group. Review of packages for r for market data downloading and analysisVyacheslav Arbuzov
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavVyacheslav Arbuzov
 
imager package in R and examples..
imager package in R and examples..imager package in R and examples..
imager package in R and examples..
Dr. Volkan OBAN
 
Advanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part IIAdvanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part II
Dr. Volkan OBAN
 
Data visualization using the grammar of graphics
Data visualization using the grammar of graphicsData visualization using the grammar of graphics
Data visualization using the grammar of graphics
Rupak Roy
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
Happy Garg
 
Geo Spatial Plot using R
Geo Spatial Plot using R Geo Spatial Plot using R
Geo Spatial Plot using R
Rupak Roy
 
Mosaic plot in R.
Mosaic plot in R.Mosaic plot in R.
Mosaic plot in R.
Dr. Volkan OBAN
 
Data visualization with multiple groups using ggplot2
Data visualization with multiple groups using ggplot2Data visualization with multiple groups using ggplot2
Data visualization with multiple groups using ggplot2
Rupak Roy
 
Py lecture5 python plots
Py lecture5 python plotsPy lecture5 python plots
Py lecture5 python plots
Yoshiki Satotani
 
NumPy Refresher
NumPy RefresherNumPy Refresher
NumPy Refresher
Lukasz Dobrzanski
 
Numpy python cheat_sheet
Numpy python cheat_sheetNumpy python cheat_sheet
Numpy python cheat_sheet
Nishant Upadhyay
 
C++ ammar .s.q
C++  ammar .s.qC++  ammar .s.q
C++ ammar .s.q
ammarsalem5
 
Experement no 6
Experement no 6Experement no 6
Experement no 6
Smita Batti
 
Python programing
Python programingPython programing
Python programing
BHAVYA DOSHI
 
Basic Calculus in R.
Basic Calculus in R. Basic Calculus in R.
Basic Calculus in R.
Dr. Volkan OBAN
 
Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.
Dr. Volkan OBAN
 
Mat lab lecture part 1
Mat lab lecture part 1Mat lab lecture part 1
Mat lab lecture part 1
OmGulshan
 

What's hot (20)

CLUSTERGRAM
CLUSTERGRAMCLUSTERGRAM
CLUSTERGRAM
 
peRm R group. Review of packages for r for market data downloading and analysis
peRm R group. Review of packages for r for market data downloading and analysispeRm R group. Review of packages for r for market data downloading and analysis
peRm R group. Review of packages for r for market data downloading and analysis
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
 
imager package in R and examples..
imager package in R and examples..imager package in R and examples..
imager package in R and examples..
 
Advanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part IIAdvanced Data Visualization Examples with R-Part II
Advanced Data Visualization Examples with R-Part II
 
Data visualization using the grammar of graphics
Data visualization using the grammar of graphicsData visualization using the grammar of graphics
Data visualization using the grammar of graphics
 
R meets Hadoop
R meets HadoopR meets Hadoop
R meets Hadoop
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Geo Spatial Plot using R
Geo Spatial Plot using R Geo Spatial Plot using R
Geo Spatial Plot using R
 
Mosaic plot in R.
Mosaic plot in R.Mosaic plot in R.
Mosaic plot in R.
 
Data visualization with multiple groups using ggplot2
Data visualization with multiple groups using ggplot2Data visualization with multiple groups using ggplot2
Data visualization with multiple groups using ggplot2
 
Py lecture5 python plots
Py lecture5 python plotsPy lecture5 python plots
Py lecture5 python plots
 
NumPy Refresher
NumPy RefresherNumPy Refresher
NumPy Refresher
 
Numpy python cheat_sheet
Numpy python cheat_sheetNumpy python cheat_sheet
Numpy python cheat_sheet
 
C++ ammar .s.q
C++  ammar .s.qC++  ammar .s.q
C++ ammar .s.q
 
Experement no 6
Experement no 6Experement no 6
Experement no 6
 
Python programing
Python programingPython programing
Python programing
 
Basic Calculus in R.
Basic Calculus in R. Basic Calculus in R.
Basic Calculus in R.
 
Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.Advanced Data Visualization in R- Somes Examples.
Advanced Data Visualization in R- Somes Examples.
 
Mat lab lecture part 1
Mat lab lecture part 1Mat lab lecture part 1
Mat lab lecture part 1
 

Viewers also liked

Hadoop 20111215
Hadoop 20111215Hadoop 20111215
Hadoop 20111215
exsuns
 
Hadoop 20111117
Hadoop 20111117Hadoop 20111117
Hadoop 20111117exsuns
 
Statistics
StatisticsStatistics
Statisticsexsuns
 
Hive data migration (export/import)
Hive data migration (export/import)Hive data migration (export/import)
Hive data migration (export/import)
Bopyo Hong
 
Which Hadoop Distribution to use: Apache, Cloudera, MapR or HortonWorks?
Which Hadoop Distribution to use: Apache, Cloudera, MapR or HortonWorks?Which Hadoop Distribution to use: Apache, Cloudera, MapR or HortonWorks?
Which Hadoop Distribution to use: Apache, Cloudera, MapR or HortonWorks?
Edureka!
 

Viewers also liked (7)

Taito
TaitoTaito
Taito
 
Hadoop 20111215
Hadoop 20111215Hadoop 20111215
Hadoop 20111215
 
Hadoop 20111117
Hadoop 20111117Hadoop 20111117
Hadoop 20111117
 
Statistics
StatisticsStatistics
Statistics
 
Hive data migration (export/import)
Hive data migration (export/import)Hive data migration (export/import)
Hive data migration (export/import)
 
Which Hadoop Distribution to use: Apache, Cloudera, MapR or HortonWorks?
Which Hadoop Distribution to use: Apache, Cloudera, MapR or HortonWorks?Which Hadoop Distribution to use: Apache, Cloudera, MapR or HortonWorks?
Which Hadoop Distribution to use: Apache, Cloudera, MapR or HortonWorks?
 
Ios
IosIos
Ios
 

Similar to R

Data analysis with R
Data analysis with RData analysis with R
Data analysis with R
ShareThis
 
R programming language
R programming languageR programming language
R programming language
Alberto Minetti
 
Big datacourse
Big datacourseBig datacourse
Big datacourse
Massimiliano Ruocco
 
R and data mining
R and data miningR and data mining
R and data mining
Chaozhong Yang
 
R Programming.pptx
R Programming.pptxR Programming.pptx
R Programming.pptx
kalai75
 
Language R
Language RLanguage R
Language R
Girish Khanzode
 
R programming
R programmingR programming
R programming
Pramodkumar Jha
 
R for you
R for youR for you
R for you
Andreas Chandra
 
Day 1d R structures & objects: matrices and data frames.pptx
Day 1d   R structures & objects: matrices and data frames.pptxDay 1d   R structures & objects: matrices and data frames.pptx
Day 1d R structures & objects: matrices and data frames.pptx
Adrien Melquiond
 
R language, an introduction
R language, an introductionR language, an introduction
R language, an introduction
Venkatesh Prasad Ranganath
 
R training3
R training3R training3
R training3
Hellen Gakuruh
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
decoupled
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
Aleksandar Veselinovic
 
Python Cheat Sheet Presentation Learning
Python Cheat Sheet Presentation LearningPython Cheat Sheet Presentation Learning
Python Cheat Sheet Presentation Learning
Naseer-ul-Hassan Rehman
 
A quick introduction to R
A quick introduction to RA quick introduction to R
A quick introduction to R
Angshuman Saha
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
Sander Kieft
 
Week7
Week7Week7
Ggplot2 v3
Ggplot2 v3Ggplot2 v3
Ggplot2 v3
Josh Doyle
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Chia-Chi Chang
 

Similar to R (20)

Data analysis with R
Data analysis with RData analysis with R
Data analysis with R
 
R programming language
R programming languageR programming language
R programming language
 
Big datacourse
Big datacourseBig datacourse
Big datacourse
 
R and data mining
R and data miningR and data mining
R and data mining
 
R Programming.pptx
R Programming.pptxR Programming.pptx
R Programming.pptx
 
Language R
Language RLanguage R
Language R
 
R programming
R programmingR programming
R programming
 
R for you
R for youR for you
R for you
 
Day 1d R structures & objects: matrices and data frames.pptx
Day 1d   R structures & objects: matrices and data frames.pptxDay 1d   R structures & objects: matrices and data frames.pptx
Day 1d R structures & objects: matrices and data frames.pptx
 
R language, an introduction
R language, an introductionR language, an introduction
R language, an introduction
 
R training3
R training3R training3
R training3
 
An overview of Python 2.7
An overview of Python 2.7An overview of Python 2.7
An overview of Python 2.7
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
Python Cheat Sheet Presentation Learning
Python Cheat Sheet Presentation LearningPython Cheat Sheet Presentation Learning
Python Cheat Sheet Presentation Learning
 
R Functions in Dataframe.pptx
R Functions in Dataframe.pptxR Functions in Dataframe.pptx
R Functions in Dataframe.pptx
 
A quick introduction to R
A quick introduction to RA quick introduction to R
A quick introduction to R
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Week7
Week7Week7
Week7
 
Ggplot2 v3
Ggplot2 v3Ggplot2 v3
Ggplot2 v3
 
Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)Learning notes of r for python programmer (Temp1)
Learning notes of r for python programmer (Temp1)
 

Recently uploaded

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 

Recently uploaded (20)

Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 

R

  • 1. R Language note
  • 2. Data analysis and graphics with R • R is a language and environment for statistical computing and graphics, similar to the S language originally developed at Bell Labs
  • 3. Common commands • getwd() 读工作目录. • setwd(“c:/”) 改变工作目录 • ls() 显示当前workspace的变量 • rm(objectlist) Remove (delete) one or more objects. • options() View or set current options. • savehistory("myfile") Save the commands history to myfile ( default = • .Rhistory). • loadhistory("myfile") Reload a command's history (default = .Rhistory). • save.image("myfile") Save the workspace to myfile (default = .RData). • save(objectlist,file="myfile") Save specific objects to a file. • load("myfile") Load a workspace into the current session (default = • .RData).
  • 5. Vector • Vector – c (2,3,1,6,5,2) – X = c (1:9) – X*2 向量乘 • 2,4,6,8,10,12,14,16,18
  • 6. Array • array(c(1:9), dim=c(3,3)) – [,1] [,2] [,3] – [1,] 1 4 7 – [2,] 2 5 8 – [3,] 3 6 9
  • 7. Matrix myymatrix <- matrix( vector, nrow=number_of_rows, ncol=number_of_columns, byrow=logical_value, dimnames=list( char_vector_rownames, char_vector_colnames ) ) M = matrix(c(1:10), nrow=2, ncol=5, byrow=T) byrow=T横向填充 byrow=F竖向填充 [,1] [,2] [,3] [,4] [,5] [,1] [,2] [,3] [,4] [,5] [1,] 1 2 3 4 5 [1,] 1 3 5 7 9 [2,] 6 7 8 9 10 [2,] 2 4 6 8 10
  • 8. Matrix a=matrix(c(1:10), nrow=2, ncol=5, byrow=T, dimnames=list(c('R1','R2'),c('a','b','c','d','e'))) abcd e R1 1 2 3 4 5 R2 6 7 8 9 10 • 选择数据: – a[1,2] 结果:2 – a[2,c(3:5)] 结果:8,9,10
  • 9. Array • n1=c('r1','r2') • n2=c('col1','col2','col3') • n3=c('p1','p2','p3','p4') •array(c(1:24),c(2,3,4),dimnames=list(n1,n2,n3) ) 三维 数组
  • 10. data frame • name=c('jack','tom','joe','linda') • age=c('21','23','20','19') • city=c('bj','sh','sh','bj') • d = data.frame(name,age,city) • Query: – d['age'] – d[c('age','city')] – d[1:2] – d$age • Edit: – d = edit(d)
  • 11. data frame • table(d$city,d$name) – jack joe linda tom – bj 1 0 1 0 – sh 0 1 0 1 attach(d) with(d,{ summary(name) summary(name) … … detach(d) })
  • 12. Lists • Lists are the most complex of the R data types • g <- "My First List" • h <- c(25, 26, 18, 39) • j <- matrix(1:10, nrow=5) • k <- c("one", "two", "three") • mylist <- list(title=g, ages=h, j, k)
  • 14. data input • mydata <- data.frame(age=numeric(0), gender=char acter(0), weight=numeric(0)) mydata <- edit(mydata) • mydataframe = read.table("c:/a.txt", header=FALSE, sep="t", row.names="name") – header:是否把第一行作为column name – row.names:标识
  • 15. data input • read excel: – library(RODBC) – channel <- odbcConnectExcel("c:/t.xlsx") – mydataframe <- sqlFetch(channel, "Sheet1") – odbcClose(channel) • excel2007: – library(xlsx) – workbook <- "c:/myworkbook.xlsx" – mydataframe <- read.xlsx(workbook, 1)
  • 16. data input • library(RODBC) • myconn <-odbcConnect("mydsn", uid="Rob", pwd="aardvark") • crimedat <- sqlFetch(myconn, Crime) • pundat <- sqlQuery(myconn, "select * from Punishment") • close(myconn)
  • 17. data export • png(), jpeg(), • bmp(), tiff(), xfig() • pdf("mygraph.pdf") • ……. • dev.off()