R programming for absolute beginners.
Recap of our pilot webinar on installing R Studio and running basic R commands
Welcome to our new subscribers. To help tailor your content, please take a moment to drop your level of R knowledge (0=newbie to 5=expert) and how you intend to apply R in your day to day life.
Last week, we had our pilot session of a free webinar walking people through the very first steps of getting started as an R programmer for complete beginners. Below is a recap of the pilot tutorial. Reminder to subscribe so you will get notified of our upcoming webinars.
Intro
Welcome to the Introduction to R Programming tutorial! This step-by-step guide will help you learn the basics of R, a powerful language used for statistical computing, data analysis, and visualization.
Prerequisites
No prior programming experience is required.
Register for free version of ChatGPT or Generative AI
Below is a recap or our pilot coding exercise as well as the ChatGPT prompts that helped us get through the session.
# 1. Getting Started with R
# What is R?
# R is a language and environment for statistical computing and graphics. It is widely used among statisticians and data miners.
# Basic R Operations
# Let’s start by learning some basic commands in R. Open RStudio or R terminal and follow along.
# This is a comment.
# This is my first R script
# I feel a little bit nervous because I am new to R
# R pilot session - Oct 12 2024.
# Example 1: Basic Arithmetic in R
# Addition
2 + 3
# Subtraction
5 - 2
# Multiplication
4 * 3
# Division
10 / 2
Output:
[1] 5
[1] 3
[1] 12
[1] 5
# Example 2: Assigning Variables
#You can store the results of calculations in variables.
# Assign values to variables
a <- 10
b <- 5
# Perform operations using variables
result <- a + b
result
# in R <- can be replaced with =
result = a + b
result
# syntax
a = 1+1 # this is a command 1
a
# a<- this is called an assignment operator
# highlight your code,
# then either click on run or control+enter
# R usually ignores blank space
1 + 1
1+1
# R is case sensitive
a = 1+1
a
A
Mango = 10
mango = 100
MANGO = 1000
maNgo = 1
maNgo
Mango = 10000
#All the above variantions are considered different by R. Always best to use lower case consistently when naming things in R
Mango # Proper Case
mango # lower case
MANGO # UPPER CASE
a = 2
a*a
# numeric
a = "Apple"
b = "Bag"
# character or string object
a
b
c = "Cat"
c
# character or string
# print command
a = 1+1
a
print(a)
print(mango)
print(c)
# vectors
a = 2
print(a)
a = c(1,2,3,4,5)
# c() stands for a collection of things
# a is a vector
print(a)
b = "bag"
print(b)
# b = c("bag", "boy", "balloon", "bubble)
#This code will return an error due to missing " before )
b = c("bag", "boy", "balloon", "bubble")
# Make sure all words are in quotes.
print(b)
# So far we have coverd syntax, assignment operator, [= OR <-], and print command,
# vector selection
a = c(1,2,3,4,5)
#we use square brackets to select the item we want from a vector
a[1]
a = c(5,4,3,2,1, 0, -1, -15)
a[1]
b[1]
# functions
print(a)
print(a[1])
# print function
a = c(5,4,3,2,1, 0)
sum(a)
print(b)
#sum(b)
mean(a)
median(a)
#importing resident doctors dataset
residentdoctors.dataset = read.csv("~/residentdoctors dataset.csv")
#Viewing resident doctors dtaaset
View(residentdoctors.dataset)
# 1 - success
# 2 - tried but not yet succeeded
# $ sign in r code is used to select a column from a dataset
residentdoctors.dataset$age
# a vector of numbers
# lets begin exploring some stats from our dataset
mean(residentdoctors.dataset$age)
median(residentdoctors.dataset$age)
hist(residentdoctors.dataset$age)
hist(residentdoctors.dataset$mentalhealth_score)
Here the ChatGPT prompts we used along the way:
Why is r so hard?
Can you use very simple language? I am new to R
I am very new to R. Where do I start?
This is too complicated. Make it easier for me to understand
What is R syntax? Give me very simple examples. I am new to R
What is the use of hashtag sign in R?
This is too complicated can you simplify the explanation?
Why am I having this error? I am sad :)
I dont understand. Explain it to me like I am 5 years old
I am confused. My code is not working
Explain it further. I am still confused
I am very green and new to R. How do I start? Any recommendation?
I am confused. My code is not working
give me a simple example of how r functions work
This is too difficult. Make it simple
I have a dataset file called residentdoctors dataset.csv can you write r code to import and view the file?
what does this mean? ("path/to/your/residentdoctors dataset.csv") My file is saved in my documents folder
This is where my file is saved at. Please write code to import it C:\Users\name\OneDrive\Documents
Explain what each line of code is doing here.