Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

RStudio Cheat Sheet with Commands Examples, Cheat Sheet of Advanced Computer Programming

A list of statistical commands to be performed in Rstudio using R language

Typology: Cheat Sheet

2020/2021

Uploaded on 04/26/2021

ananya
ananya 🇺🇸

4.4

(16)

11 documents

Partial preview of the text

Download RStudio Cheat Sheet with Commands Examples and more Cheat Sheet Advanced Computer Programming in PDF only on Docsity! Cheat Sheet for R and RStudio L. Jason Anastasopoulos April 29, 2013 1 Downloading and Installation • First download R for your OS: R • Next download RStudio for your OS: RStudio 2 Uploading Data into R-Studio R-Studio Makes uploading CSV files into R extremely simple. Just follow these instructions and you’ll be using R in no time. 1. Download your .csv data to a folder that you can easily find. 2. Open R-Studio. 3. In the interpreter (lower left-hand box of RStudio), type library(foreign) and hit Enter. This will install the package that reads your .csv files. 4. In the box on the upper-right hand corner of RStudio, click on the tab that says “Workspace”. 5. Then click on “Import Dataset > From Text File...”. Find your .csv dataset and open it. 6. In the interpreter (lower left-hand box), type in attach(name-of-dataset) and hit En- ter. You can find the name of the dataset listed under the “Workspace” tab in the upper right-hand corner of RStudio. 7. To find the variable names in your dataset type names(name-of-dataset) and hit Enter. 1 3 Doing Statistics in RStudio After you have opened your data, doing statistics is really easy. Below is a list of commands that you will need to do any kind of statistics in RStudio. 3.1 Summary Statistics • summary(X) - Summary statistics such as mean,median,mode and quartiles for a variable. > summary(X) Min. 1st Qu. Median Mean 3rd Qu. Max. -3.0360 -0.8855 -0.2475 -0.2382 0.3345 3.4460 • mean(X,na.rm=TRUE) - Produces the mean of the variable. Removes missing observations. > mean(X,na.rm=TRUE) [1] -0.2382041 • sd(X,na.rm=TRUE) - Produces the standard deviation of the variable. Removes missing observations. > sd(X,na.rm=TRUE) [1] 0.9604155 3.2 Regression • lm(Y ∼ X) - Runs a regression of Y on X where Y is your dependent variable and X is your independent variable. You need to save your model in R’s memory first and can get the regression coefficients and other info you need by using the summary() command. For example, for simple regression: > model1 = lm(Y~X) > summary(model1) Call: lm(formula = Y ~ X) Residuals: Min 1Q Median 3Q Max 2 sample estimates: mean of x mean of y -0.2382041 -0.2056246 3.4 Graphics and Plots • hist(X) - Will produce a histogram of the variable X. > hist(X) • plot(X,Y) - Will produce a scatterplot of the variables X and Y with X on the x-axis and Y on the y-axis. > plot(X,Y) 5 6
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved