MATH 1280 R Commands Cheat Sheet- University of the People
20 views 0 purchase
Course
MATH 1280
Institution
MATH 1280
MATH 1280 R Commands Cheat Sheet- University of the PeopleMATH 1280 R Commands Cheat Sheet- University of the PeopleMATH 1280 R Commands Cheat Sheet- University of the PeopleMATH 1280 R Commands Cheat Sheet- University of the PeopleMATH 1280 R Commands Cheat Sheet- University of the PeopleMATH 1280...
Create an R Object
> X <- c(5,5.5,6,6,6,6.5,6.5,6.5,6.5,7,7,8,8,9)
Table Function
> table()
Example: table(X)
Bar Plot
> plot(table(X))
WEEK 2
Data Frame a Table
> data.frame(table(work.hours))
Storing a Table's Frequencies with the freq Function
> freq <- table(work.hours)
Sum of The Frequency
> sum(freq)
A sequence of relative frequencies
> sum(freq/sum(freq))
The cumulative relative frequency is the accumulation of previous relative
frequencies.
Using the cumsum function:
> cumsum(freq/sum(freq))
Setting Working Directory
Change R's Working Directory: Right click on R Icon, Properties, change Start In path.
Check Working Directory
> getwd()
Reading of files in the CSV format
> ex.1 <- read.csv("ex1.csv")
Table the data of a specific column
> table(flower.data$Sepal.Width)
Plot a table of data of a specific column
>plot(table(flower.data$Sepal.Width))
, WEEK 3
Histogram
> hist(ex.1$height)
Sum of a specific column
> sum(ex.1$height)
The sum of the cumulative frequency, of a table of data for a specific column
> cumsum(table(ex.1$height))
Finding Quartiles
Use either the summary() or quartile() commands. However summary() is easiest.
Creating a boxplot
> boxplot(c(1,11.5,6,7.2,4,8,9,10,6.8,8.3,2,2,10,1))
Boxplot of a specific data column
> boxplot(ex.1$height)
Summary of a data column
> summary(ex.1$height)
R Function for mean
> mean(x)
R Function for median
> median(x)
Mean of a column
> mean(ex.1$height)
Medium of a column
> median(ex.1$height)
The Length Command (counts the number of observations)
> length(x)
Assign mean to an object
> x.bar <- mean(x)
Finding deviation
> x - x.bar
Computation of the squares of the deviations
> (x - x.bar)^2
Variance
> sum((x - x.bar)^2)/(length(x)-1)
or
> var(x)
Standard Deviation
> sqrt(sum((x - x.bar)^2)/(length(x)-1))
or
> sd(x)
WARNING: use the var() and sd() R commands only if you have all the data from a sample.
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller Timeless2024. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $16.99. You're not tied to anything after your purchase.