Download presentation
Presentation is loading. Please wait.
1
Basic statistics on a vector in R
2
Suppose we had a vector corresponding to high temperatures in Philadelphia in August
high_temps<-c(91, 89, 87, 88, 79, 78, 72, 80, 86, 86, 84, 83, 84, 82, 78, 89, 90, 91, 88, 85, 87, 92, 84, 82, 79, 81, 79, 77, 67, 78, 84) We will consider another time how to get data from Excel to R or vice versa, but for now just copy the above code into R For now we just want to focus on some of the simple statistic functions built into R that can act on a vector
3
Open RStudio. Seems like there’s some old stuff in the Environment
4
Click on the List icon (upper right) and switch to Grid.
5
Check the “objects” and use the broom icon to clear them out.
6
Start a new script
7
Save it
8
Copy and paste the data into RStudio and run it
high_temps<-c(91, 89, 87, 88, 79, 78, 72, 80, 86, 86, 84, 83, 84, 82, 78, 89, 90, 91, 88, 85, 87, 92, 84, 82, 79, 81, 79, 77, 67, 78, 84) The keyboard shortcut for copying is Ctrl-c (copies whatever is highlighted) The keyboard shortcut for pasting is Ctrl-v The run, place the cursor on the line (or highlight it) and click on the Run icon (or type Ctrl-Enter)
9
Result of paste and run
10
Use the mean function to calculate the average
11
Use the median function
12
Use the sd (standard deviation) function
13
Use the min() function – minimum
14
Use the max() function – maximum
15
The quantile function can be used to determine the first quartile
16
The quantile function can be used to determine the third quartile
17
The summary function is a quick way to get a number of standard statistical measures on a set of data
18
To do Give the statistical measures for the low temperature data
low_temps <- c(71, 69, 67, 72, 68, 63, 66, 66, 64, 67, 68, 70, 70, 67, 72, 69, 69, 75, 73, 68, 67, 73, 68, 65, 65, 65, 62, 60, 62, 60, 66) Get individually the mean, median, standard deviation, min, max, first and third quartiles Submit your R script
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.