Go though LabAssignment1.pdf
LabAssignment1.pdf
Download and open LabAssignment1.Rmd
LabAssignment1.Rmd in RStudio and run codes!
Open template.Rmd
and save as a new .Rmd file for your Lab Assignment submission. Edit the author name, date and content.
Copy the codes in LabAssignment1.Rmd
to your new .Rmd file and run the codes.
Try to modify the codes according to the instruction in LabAssignment1.pdf
. Run and see if you can get some numbers. Knit to see how the .pdf looks like.
Tidy up the codes and writings. Knit and submit!
Follow the below instructions to make yourself comfortable in using R/RStudio for statistical/scientific computing.
Working directory is the default folder in which files are saved and read.
In the Files tab, find/create a folder for your STA100 work. Click More then Set As Working Directory.
Open the R script you worked on last week. Run the codes.
Working directory is not persistent after you you close the R/RStudio. Remember to set working directory each time you open a R/RStudio.
2.5
and standard deviation 1.2
n <- 1000
x <- rnorm(n, mean = 2.5, sd = 1.2)
hist(x)
mean(x)
## [1] 2.508808
sd(x)
## [1] 1.196989
Let’s draw random samples from BTS
bts <- c("Jin", "Suga", "J-Hope", "RM", "Jimin", "V", "Jungkook")
What is the size of bts
?
length(bts)
## [1] 7
Sampling!
subgroup_a <- sample(bts, 4, replace = FALSE)
subgroup_b <- sample(bts, 4, replace = FALSE)
subgroup_a
## [1] "Suga" "Jimin" "J-Hope" "V"
subgroup_b
## [1] "Jungkook" "Suga" "Jin" "J-Hope"
What are the union and intersection of the subgroups?
union(subgroup_a, subgroup_b)
## [1] "Suga" "Jimin" "J-Hope" "V" "Jungkook" "Jin"
intersect(subgroup_a, subgroup_b)
## [1] "Suga" "J-Hope"
Set | Elements | Size |
---|---|---|
BTS (Population) | Jin, Suga, J-Hope, RM, Jimin, V, Jungkook | 7 |
Subgroup A (Sample) | Suga, Jimin, J-Hope, V | 4 |
Subgroup B (Sample) | Jungkook, Suga, Jin, J-Hope | 4 |
A or B (Union) | Suga, Jimin, J-Hope, V, Jungkook, Jin | 6 |
A and B (Intersect) | Suga, J-Hope | 2 |
Read the R Documentation of the functions you learn today. Enter the following codes, one by one, and read the corresponding documentation/help in the Help tab.
?rnorm
?mean
?sd
?hist
?length
?sample
?union
?intersect
How Po knows all those built-in functions in R?
Way 1: Google it
Way 2: Read R Help/Documentation
Give a man a fish and you feed him for a day; Teach a man to fish and you feed him for a lifetime.
Po | Codes in labs | R Documentation | |
---|---|---|---|
Fisherman | Fish | Fish Rod | Sea |
Interactive R course lessons swirl https://swirlstats.com/students.html
Install swirl with the following commands.
# If you haven't installed the swirl package yet
install.packages("swirl")
library(swirl)
install_course_github("swirldev", "R_Programming_E")
After swirl is installed (you only need to do it once), you can start/resume the R tutorial with the commands:
library(swirl)
swirl()
Schedule some time to go though all the lessons by yourself! Almost all of the R codes you need to know are here in those lessons.
If you prefer more static readings (Po did read them to learn R!):
If you like RStudio’s data science things,