SlideShare a Scribd company logo
1 of 30
Download to read offline
A simple introduction to R
for market researchers
October
2019
Webinar Friday 4 October
Live broadcast 10am New York (3pm London)
Ray Poynter
Chief Research Officer, Potentiate
What is R?
• An open-source, free statistical language
• The core language is expanded by an enormous collection of
libraries
• Available for Windows, Mac and UNIX
• Find out about R (& download it) from: -
https://www.r-project.org/
• Learning R
• Books
• Articles
• Videos
• E-learning, e.g. DataCamp, Udemy & Coursera
What is RStudio?
• There are other choices, but nearly everybody I know
is using RStudio to work with R
• It is an IDE (Integrated Development Environment)
• Editor
• A tidy place to run R, to see the variables, and keep things tidy
• There are open-source and commercial options (free and
not-free)
• Find out more and download it from https://rstudio.com/
Commands and R
Commands are entered in the Console window
Commands and R – Hello World
> print("Hello World")
[1] "Hello World"
>
> print("Hello World", quote=FALSE)
[1] Hello World
>
> myText <- "Hello World"
> print(myText)
[1] "Hello World"
>
> myText
[1] "Hello World"
>
Commands and R – Variables
> a <- 2
> b <- 4
> print(a * b)
[1] 8
>
> c <- a * b
> c
[1] 8
>
> c <- "Hello World"
> c
[1] "Hello World"
>
Commands and R – Vectors
> x <- c(1,2,3,4)
> x
[1] 1 2 3 4
> y <- 2 * x
> y
[1] 2 4 6 8
> z <- c("One","Two","Three")
> z
[1] "One" "Two" "Three"
Commands and R – Data sets
R has lots of built in data sets. For example, mtcars
> str(mtcars)
'data.frame': 32 obs. of 11 variables:
$ mpg :Class 'labelled' num 21 21 22.8 21.4 18.7 18.1 14.3
24.4 22.8 19.2 ...
.. .. LABEL: Miles/(US) gallon
$ cyl :Class 'labelled' num 6 6 4 6 8 6 8 4 4 6 ...
.. .. LABEL: Number of cylinders
And 9 more variables
mtcars
Use help (or ?) to understand an included data set
> ?mtcars
mtcars {datasets} R Documentation
Motor Trend Car Road Tests
Description
The data was extracted from the 1974 Motor Trend US magazine, and
comprises fuel consumption and 10 aspects of automobile design and
performance for 32 automobiles (1973–74 models).
Usage
Mtcars
Format
A data frame with 32 observations on 11 (numeric) variables.
Commands and R – Data Frames
Data Frame – a compound structure,
where the rows can be different sorts of items.
> head(mtcars,4)
mpg cyl disp hp drat wt qsec vs am gear carb
Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
Commands and R – Frames and Vectors
We can address vectors from inside a data frame using $
> summary(mtcars$mpg)
Min. 1st Qu. Median Mean 3rd Qu. Max.
10.40 15.43 19.20 20.09 22.80 33.90
>
Commands and R – simple chart
> hist(mtcars$mpg)
Commands and R - libraries
The real power of R comes from the installed libraries
> install.packages("ggplot2")
trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/ggplot2_3.2.1.tgz'
Content type 'application/x-gzip' length 3973186 bytes (3.8 MB)
==================================================
downloaded 3.8 MB
The downloaded binary packages are in
/var/folders/wp/n9tjrcps0990gpznfmpqff2h0000gn/T//RtmpXDhlrV/downloaded_packages
> library(ggplot2)
>
> ggplot(mtcars, aes(x=hp, y=mpg)) +
geom_point(aes(shape=factor(cyl), colour=factor(cyl))) +
xlab("Performance (horse power)") +
ylab("Fuel consumption (mpg)")+
ggtitle("More cylinders are associated with fewer miles per gallon") +
scale_shape_discrete(name="Cylinders") +
scale_colour_discrete(name="Cylinders")
ggplot2 example
Scripts and R
Scripts are the best way to use R
• You create a record of what you did
• You can tweak the code
• You can audit the code
• You can re-use the code for other projects
• Comment your code to make it readable
Scripts and R
Console
From the Script
1. Run the whole script
2. Select and run a section
3. Run a single line
The code and the results appear in
the Console
Scripts and Charting Example
Plots go in the plot window
and can be exported
Tables and R
The Iris Data Set
> data(iris)
> ?iris
Edgar Anderson's Iris Data
Description
This famous (Fisher's or Anderson's) iris data set gives the measurements in
centimeters of the variables sepal length and width and petal length and width,
respectively, for 50 flowers from each of 3 species of iris. The species are Iris
setosa, versicolor, and virginica.
iris is a data frame with 150 cases (rows) and 5 variables (columns)
named Sepal.Length, Sepal.Width, Petal.Length, Petal.Width, and Species.
Principal Components and Charting Example
> head(pca_mod,2)
$sdev
[1] 2.0562689 0.4926162 0.2796596 0.1543862
$rotation
PC1 PC2 PC3 PC4
Sepal.Length 0.36138659 -0.65658877 0.58202985 0.3154872
Sepal.Width -0.08452251 -0.73016143 -0.59791083 -0.3197231
Petal.Length 0.85667061 0.17337266 -0.07623608 -0.4798390
Petal.Width 0.35828920 0.07548102 -0.54583143 0.7536574
Principal Components
and Charting Example
Principal Components
and Charting Example
Text tools
This example uses ‘The Wonderdul Wizard of Oz, by L. Frank Baum
downloaded from Project Gutenberg http://www.gutenberg.org/ebooks/55
Tidy the text
Bar chart of common words
Word cloud
Digging deeper
Overview
• Free and open-source
• Massive collection of libraries
• Stats
• Text analytics
• AI tools
• Graphics
• Relatively steep learning curve
• More about finding the story than telling the story
• Lots of resources for learning about R
• Books, videos, courses, papers etc
Q & A
Ray Poynter
Chief Research Officer
Potentiate
October
2019
#NewMR Sponsors
October
2019
Communication
Gold
Silver

More Related Content

Similar to A Simple Introduction to R for Market Researchers

Introduction to R for Learning Analytics Researchers
Introduction to R for Learning Analytics ResearchersIntroduction to R for Learning Analytics Researchers
Introduction to R for Learning Analytics ResearchersVitomir Kovanovic
 
Research paper presentation
Research paper presentation Research paper presentation
Research paper presentation Akshat Sharma
 
Unit1_Introduction to R.pdf
Unit1_Introduction to R.pdfUnit1_Introduction to R.pdf
Unit1_Introduction to R.pdfMDDidarulAlam15
 
Lect05 Prog Model
Lect05 Prog ModelLect05 Prog Model
Lect05 Prog Modelanoosdomain
 
BUSINESS ANALYTICS WITH R SOFTWARE DIAST
BUSINESS ANALYTICS WITH R SOFTWARE DIASTBUSINESS ANALYTICS WITH R SOFTWARE DIAST
BUSINESS ANALYTICS WITH R SOFTWARE DIASTHaritikaChhatwal1
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxVigneshkumar Ponnusamy
 
Unit 2 - Data Manipulation with R.pptx
Unit 2 - Data Manipulation with R.pptxUnit 2 - Data Manipulation with R.pptx
Unit 2 - Data Manipulation with R.pptxMalla Reddy University
 
An introduction to R is a document useful
An introduction to R is a document usefulAn introduction to R is a document useful
An introduction to R is a document usefulssuser3c3f88
 
Data Analytics with R and SQL Server
Data Analytics with R and SQL ServerData Analytics with R and SQL Server
Data Analytics with R and SQL ServerStéphane Fréchette
 
Training in Analytics, R and Social Media Analytics
Training in Analytics, R and Social Media AnalyticsTraining in Analytics, R and Social Media Analytics
Training in Analytics, R and Social Media AnalyticsAjay Ohri
 
An R primer for SQL folks
An R primer for SQL folksAn R primer for SQL folks
An R primer for SQL folksThomas Hütter
 
Big data analytics with R tool.pptx
Big data analytics with R tool.pptxBig data analytics with R tool.pptx
Big data analytics with R tool.pptxsalutiontechnology
 
STAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdf
STAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdfSTAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdf
STAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdfSOUMIQUE AHAMED
 
Analytics Beyond RAM Capacity using R
Analytics Beyond RAM Capacity using RAnalytics Beyond RAM Capacity using R
Analytics Beyond RAM Capacity using RAlex Palamides
 
Introduction to basic statistics
Introduction to basic statisticsIntroduction to basic statistics
Introduction to basic statisticsIBM
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine LearningAmanBhalla14
 
DATA MINING USING R (1).pptx
DATA MINING USING R (1).pptxDATA MINING USING R (1).pptx
DATA MINING USING R (1).pptxmyworld93
 
ARM_System_Developers_Guide-Designing_and_Optimizing_System_Software.pdf
ARM_System_Developers_Guide-Designing_and_Optimizing_System_Software.pdfARM_System_Developers_Guide-Designing_and_Optimizing_System_Software.pdf
ARM_System_Developers_Guide-Designing_and_Optimizing_System_Software.pdfKNaveenKumarECE
 

Similar to A Simple Introduction to R for Market Researchers (20)

Introduction to R for Learning Analytics Researchers
Introduction to R for Learning Analytics ResearchersIntroduction to R for Learning Analytics Researchers
Introduction to R for Learning Analytics Researchers
 
Research paper presentation
Research paper presentation Research paper presentation
Research paper presentation
 
Unit1_Introduction to R.pdf
Unit1_Introduction to R.pdfUnit1_Introduction to R.pdf
Unit1_Introduction to R.pdf
 
Decision trees in hadoop
Decision trees in hadoopDecision trees in hadoop
Decision trees in hadoop
 
Lect05 Prog Model
Lect05 Prog ModelLect05 Prog Model
Lect05 Prog Model
 
BUSINESS ANALYTICS WITH R SOFTWARE DIAST
BUSINESS ANALYTICS WITH R SOFTWARE DIASTBUSINESS ANALYTICS WITH R SOFTWARE DIAST
BUSINESS ANALYTICS WITH R SOFTWARE DIAST
 
Fundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptxFundamentals of Data Structures Unit 1.pptx
Fundamentals of Data Structures Unit 1.pptx
 
Unit 2 - Data Manipulation with R.pptx
Unit 2 - Data Manipulation with R.pptxUnit 2 - Data Manipulation with R.pptx
Unit 2 - Data Manipulation with R.pptx
 
An introduction to R is a document useful
An introduction to R is a document usefulAn introduction to R is a document useful
An introduction to R is a document useful
 
Data Analytics with R and SQL Server
Data Analytics with R and SQL ServerData Analytics with R and SQL Server
Data Analytics with R and SQL Server
 
Training in Analytics, R and Social Media Analytics
Training in Analytics, R and Social Media AnalyticsTraining in Analytics, R and Social Media Analytics
Training in Analytics, R and Social Media Analytics
 
An R primer for SQL folks
An R primer for SQL folksAn R primer for SQL folks
An R primer for SQL folks
 
Big data analytics with R tool.pptx
Big data analytics with R tool.pptxBig data analytics with R tool.pptx
Big data analytics with R tool.pptx
 
STAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdf
STAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdfSTAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdf
STAT-522 (Data Analysis Using R) by SOUMIQUE AHAMED.pdf
 
Analytics Beyond RAM Capacity using R
Analytics Beyond RAM Capacity using RAnalytics Beyond RAM Capacity using R
Analytics Beyond RAM Capacity using R
 
R tutorial
R tutorialR tutorial
R tutorial
 
Introduction to basic statistics
Introduction to basic statisticsIntroduction to basic statistics
Introduction to basic statistics
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine Learning
 
DATA MINING USING R (1).pptx
DATA MINING USING R (1).pptxDATA MINING USING R (1).pptx
DATA MINING USING R (1).pptx
 
ARM_System_Developers_Guide-Designing_and_Optimizing_System_Software.pdf
ARM_System_Developers_Guide-Designing_and_Optimizing_System_Software.pdfARM_System_Developers_Guide-Designing_and_Optimizing_System_Software.pdf
ARM_System_Developers_Guide-Designing_and_Optimizing_System_Software.pdf
 

More from Ray Poynter

The State of AI in Insights and Research 2024: Results and Findings
The State of AI in Insights and Research 2024: Results and FindingsThe State of AI in Insights and Research 2024: Results and Findings
The State of AI in Insights and Research 2024: Results and FindingsRay Poynter
 
ResearchWiseAI - an artificial intelligence driven research data analysis tool
ResearchWiseAI - an artificial intelligence driven research data analysis toolResearchWiseAI - an artificial intelligence driven research data analysis tool
ResearchWiseAI - an artificial intelligence driven research data analysis toolRay Poynter
 
AI-powered interviewing: Best practices from Yasna
AI-powered interviewing: Best practices from YasnaAI-powered interviewing: Best practices from Yasna
AI-powered interviewing: Best practices from YasnaRay Poynter
 
Artificial Intelligence and Qual: The Story So Far
Artificial Intelligence and Qual: The Story So FarArtificial Intelligence and Qual: The Story So Far
Artificial Intelligence and Qual: The Story So FarRay Poynter
 
State of Research Insights in Q1, 2024 from NewMR
State of Research Insights in Q1, 2024 from NewMRState of Research Insights in Q1, 2024 from NewMR
State of Research Insights in Q1, 2024 from NewMRRay Poynter
 
Sudden Death of Beliefs
Sudden Death of BeliefsSudden Death of Beliefs
Sudden Death of BeliefsRay Poynter
 
Uncovering Consumers’ Hidden Narratives
Uncovering Consumers’ Hidden NarrativesUncovering Consumers’ Hidden Narratives
Uncovering Consumers’ Hidden NarrativesRay Poynter
 
Narrative Exploration of New Categories at Mondelēz
Narrative Exploration of New Categories at MondelēzNarrative Exploration of New Categories at Mondelēz
Narrative Exploration of New Categories at MondelēzRay Poynter
 
The Future in Focus
The Future in FocusThe Future in Focus
The Future in FocusRay Poynter
 
The Future in Focus
The Future in FocusThe Future in Focus
The Future in FocusRay Poynter
 
The State of Insights – September 2023
The State of Insights – September 2023The State of Insights – September 2023
The State of Insights – September 2023Ray Poynter
 
Research Thinking in the age of AI
Research Thinking in the age of AIResearch Thinking in the age of AI
Research Thinking in the age of AIRay Poynter
 
How might AI impact Research and Insights over the next two years?
How might AI impact Research and Insights over the next two years?How might AI impact Research and Insights over the next two years?
How might AI impact Research and Insights over the next two years?Ray Poynter
 
From Words to Wisdom: Unleashing the Potential of Language Models for Human-C...
From Words to Wisdom: Unleashing the Potential of Language Models for Human-C...From Words to Wisdom: Unleashing the Potential of Language Models for Human-C...
From Words to Wisdom: Unleashing the Potential of Language Models for Human-C...Ray Poynter
 
ChatGPT for Social Media Listening: practical application with YouScan’s Insi...
ChatGPT for Social Media Listening: practical application with YouScan’s Insi...ChatGPT for Social Media Listening: practical application with YouScan’s Insi...
ChatGPT for Social Media Listening: practical application with YouScan’s Insi...Ray Poynter
 
Using Generative AI to Assess the Quality of Open-Ended Responses in Surveys
Using Generative AI to Assess the Quality of Open-Ended Responses in SurveysUsing Generative AI to Assess the Quality of Open-Ended Responses in Surveys
Using Generative AI to Assess the Quality of Open-Ended Responses in SurveysRay Poynter
 
Exploring the future of verbatim coding with ChatGPT
Exploring the future of verbatim coding with ChatGPTExploring the future of verbatim coding with ChatGPT
Exploring the future of verbatim coding with ChatGPTRay Poynter
 
Using Generative AI to bring Qualitative Capabilities to Quantitative Surveys
Using Generative AI to bring Qualitative Capabilities to Quantitative SurveysUsing Generative AI to bring Qualitative Capabilities to Quantitative Surveys
Using Generative AI to bring Qualitative Capabilities to Quantitative SurveysRay Poynter
 
How AI / ChatGPT Drives Business Growth
How AI / ChatGPT Drives Business GrowthHow AI / ChatGPT Drives Business Growth
How AI / ChatGPT Drives Business GrowthRay Poynter
 
Tech for tech’s sake? Learnings from experiments with AI in consumer research
Tech for tech’s sake? Learnings from experiments with AI in consumer researchTech for tech’s sake? Learnings from experiments with AI in consumer research
Tech for tech’s sake? Learnings from experiments with AI in consumer researchRay Poynter
 

More from Ray Poynter (20)

The State of AI in Insights and Research 2024: Results and Findings
The State of AI in Insights and Research 2024: Results and FindingsThe State of AI in Insights and Research 2024: Results and Findings
The State of AI in Insights and Research 2024: Results and Findings
 
ResearchWiseAI - an artificial intelligence driven research data analysis tool
ResearchWiseAI - an artificial intelligence driven research data analysis toolResearchWiseAI - an artificial intelligence driven research data analysis tool
ResearchWiseAI - an artificial intelligence driven research data analysis tool
 
AI-powered interviewing: Best practices from Yasna
AI-powered interviewing: Best practices from YasnaAI-powered interviewing: Best practices from Yasna
AI-powered interviewing: Best practices from Yasna
 
Artificial Intelligence and Qual: The Story So Far
Artificial Intelligence and Qual: The Story So FarArtificial Intelligence and Qual: The Story So Far
Artificial Intelligence and Qual: The Story So Far
 
State of Research Insights in Q1, 2024 from NewMR
State of Research Insights in Q1, 2024 from NewMRState of Research Insights in Q1, 2024 from NewMR
State of Research Insights in Q1, 2024 from NewMR
 
Sudden Death of Beliefs
Sudden Death of BeliefsSudden Death of Beliefs
Sudden Death of Beliefs
 
Uncovering Consumers’ Hidden Narratives
Uncovering Consumers’ Hidden NarrativesUncovering Consumers’ Hidden Narratives
Uncovering Consumers’ Hidden Narratives
 
Narrative Exploration of New Categories at Mondelēz
Narrative Exploration of New Categories at MondelēzNarrative Exploration of New Categories at Mondelēz
Narrative Exploration of New Categories at Mondelēz
 
The Future in Focus
The Future in FocusThe Future in Focus
The Future in Focus
 
The Future in Focus
The Future in FocusThe Future in Focus
The Future in Focus
 
The State of Insights – September 2023
The State of Insights – September 2023The State of Insights – September 2023
The State of Insights – September 2023
 
Research Thinking in the age of AI
Research Thinking in the age of AIResearch Thinking in the age of AI
Research Thinking in the age of AI
 
How might AI impact Research and Insights over the next two years?
How might AI impact Research and Insights over the next two years?How might AI impact Research and Insights over the next two years?
How might AI impact Research and Insights over the next two years?
 
From Words to Wisdom: Unleashing the Potential of Language Models for Human-C...
From Words to Wisdom: Unleashing the Potential of Language Models for Human-C...From Words to Wisdom: Unleashing the Potential of Language Models for Human-C...
From Words to Wisdom: Unleashing the Potential of Language Models for Human-C...
 
ChatGPT for Social Media Listening: practical application with YouScan’s Insi...
ChatGPT for Social Media Listening: practical application with YouScan’s Insi...ChatGPT for Social Media Listening: practical application with YouScan’s Insi...
ChatGPT for Social Media Listening: practical application with YouScan’s Insi...
 
Using Generative AI to Assess the Quality of Open-Ended Responses in Surveys
Using Generative AI to Assess the Quality of Open-Ended Responses in SurveysUsing Generative AI to Assess the Quality of Open-Ended Responses in Surveys
Using Generative AI to Assess the Quality of Open-Ended Responses in Surveys
 
Exploring the future of verbatim coding with ChatGPT
Exploring the future of verbatim coding with ChatGPTExploring the future of verbatim coding with ChatGPT
Exploring the future of verbatim coding with ChatGPT
 
Using Generative AI to bring Qualitative Capabilities to Quantitative Surveys
Using Generative AI to bring Qualitative Capabilities to Quantitative SurveysUsing Generative AI to bring Qualitative Capabilities to Quantitative Surveys
Using Generative AI to bring Qualitative Capabilities to Quantitative Surveys
 
How AI / ChatGPT Drives Business Growth
How AI / ChatGPT Drives Business GrowthHow AI / ChatGPT Drives Business Growth
How AI / ChatGPT Drives Business Growth
 
Tech for tech’s sake? Learnings from experiments with AI in consumer research
Tech for tech’s sake? Learnings from experiments with AI in consumer researchTech for tech’s sake? Learnings from experiments with AI in consumer research
Tech for tech’s sake? Learnings from experiments with AI in consumer research
 

Recently uploaded

Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseAnaAcapella
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxmarlenawright1
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 

Recently uploaded (20)

Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 

A Simple Introduction to R for Market Researchers

  • 1. A simple introduction to R for market researchers October 2019 Webinar Friday 4 October Live broadcast 10am New York (3pm London) Ray Poynter Chief Research Officer, Potentiate
  • 2. What is R? • An open-source, free statistical language • The core language is expanded by an enormous collection of libraries • Available for Windows, Mac and UNIX • Find out about R (& download it) from: - https://www.r-project.org/ • Learning R • Books • Articles • Videos • E-learning, e.g. DataCamp, Udemy & Coursera
  • 3. What is RStudio? • There are other choices, but nearly everybody I know is using RStudio to work with R • It is an IDE (Integrated Development Environment) • Editor • A tidy place to run R, to see the variables, and keep things tidy • There are open-source and commercial options (free and not-free) • Find out more and download it from https://rstudio.com/
  • 4. Commands and R Commands are entered in the Console window
  • 5. Commands and R – Hello World > print("Hello World") [1] "Hello World" > > print("Hello World", quote=FALSE) [1] Hello World > > myText <- "Hello World" > print(myText) [1] "Hello World" > > myText [1] "Hello World" >
  • 6. Commands and R – Variables > a <- 2 > b <- 4 > print(a * b) [1] 8 > > c <- a * b > c [1] 8 > > c <- "Hello World" > c [1] "Hello World" >
  • 7. Commands and R – Vectors > x <- c(1,2,3,4) > x [1] 1 2 3 4 > y <- 2 * x > y [1] 2 4 6 8 > z <- c("One","Two","Three") > z [1] "One" "Two" "Three"
  • 8. Commands and R – Data sets R has lots of built in data sets. For example, mtcars > str(mtcars) 'data.frame': 32 obs. of 11 variables: $ mpg :Class 'labelled' num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ... .. .. LABEL: Miles/(US) gallon $ cyl :Class 'labelled' num 6 6 4 6 8 6 8 4 4 6 ... .. .. LABEL: Number of cylinders And 9 more variables
  • 9. mtcars Use help (or ?) to understand an included data set > ?mtcars mtcars {datasets} R Documentation Motor Trend Car Road Tests Description The data was extracted from the 1974 Motor Trend US magazine, and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973–74 models). Usage Mtcars Format A data frame with 32 observations on 11 (numeric) variables.
  • 10. Commands and R – Data Frames Data Frame – a compound structure, where the rows can be different sorts of items. > head(mtcars,4) mpg cyl disp hp drat wt qsec vs am gear carb Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4 Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4 Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1 Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
  • 11. Commands and R – Frames and Vectors We can address vectors from inside a data frame using $ > summary(mtcars$mpg) Min. 1st Qu. Median Mean 3rd Qu. Max. 10.40 15.43 19.20 20.09 22.80 33.90 >
  • 12. Commands and R – simple chart > hist(mtcars$mpg)
  • 13. Commands and R - libraries The real power of R comes from the installed libraries > install.packages("ggplot2") trying URL 'https://cran.rstudio.com/bin/macosx/el-capitan/contrib/3.6/ggplot2_3.2.1.tgz' Content type 'application/x-gzip' length 3973186 bytes (3.8 MB) ================================================== downloaded 3.8 MB The downloaded binary packages are in /var/folders/wp/n9tjrcps0990gpznfmpqff2h0000gn/T//RtmpXDhlrV/downloaded_packages > library(ggplot2) > > ggplot(mtcars, aes(x=hp, y=mpg)) + geom_point(aes(shape=factor(cyl), colour=factor(cyl))) + xlab("Performance (horse power)") + ylab("Fuel consumption (mpg)")+ ggtitle("More cylinders are associated with fewer miles per gallon") + scale_shape_discrete(name="Cylinders") + scale_colour_discrete(name="Cylinders")
  • 15. Scripts and R Scripts are the best way to use R • You create a record of what you did • You can tweak the code • You can audit the code • You can re-use the code for other projects • Comment your code to make it readable
  • 16. Scripts and R Console From the Script 1. Run the whole script 2. Select and run a section 3. Run a single line The code and the results appear in the Console
  • 17. Scripts and Charting Example Plots go in the plot window and can be exported
  • 19. The Iris Data Set > data(iris) > ?iris Edgar Anderson's Iris Data Description This famous (Fisher's or Anderson's) iris data set gives the measurements in centimeters of the variables sepal length and width and petal length and width, respectively, for 50 flowers from each of 3 species of iris. The species are Iris setosa, versicolor, and virginica. iris is a data frame with 150 cases (rows) and 5 variables (columns) named Sepal.Length, Sepal.Width, Petal.Length, Petal.Width, and Species.
  • 20. Principal Components and Charting Example > head(pca_mod,2) $sdev [1] 2.0562689 0.4926162 0.2796596 0.1543862 $rotation PC1 PC2 PC3 PC4 Sepal.Length 0.36138659 -0.65658877 0.58202985 0.3154872 Sepal.Width -0.08452251 -0.73016143 -0.59791083 -0.3197231 Petal.Length 0.85667061 0.17337266 -0.07623608 -0.4798390 Petal.Width 0.35828920 0.07548102 -0.54583143 0.7536574
  • 23. Text tools This example uses ‘The Wonderdul Wizard of Oz, by L. Frank Baum downloaded from Project Gutenberg http://www.gutenberg.org/ebooks/55
  • 25. Bar chart of common words
  • 28. Overview • Free and open-source • Massive collection of libraries • Stats • Text analytics • AI tools • Graphics • Relatively steep learning curve • More about finding the story than telling the story • Lots of resources for learning about R • Books, videos, courses, papers etc
  • 29. Q & A Ray Poynter Chief Research Officer Potentiate October 2019