Publications by Xiao Ling
STAT3000 090424
In R, the square brackets [] are used for subsetting objects such as vectors, matrices, data frames. Subsetting Vectors Positive integer index: x[1] – returns the first element. Negative integer index: x[-1] – excludes the first element. Integer range: x[1:3] – returns elements 1 through 3. Logical vector: x[x > 3] – returns elements gre...
4386 sym R (5549 sym/33 pcs)
STAT3000 090424
Sorting Ordering Now that we have mastered some basic R knowledge, let’s try to gain some insights into the safety of different states in the context of gun murders. Say we want to rank the states from least to most gun murders. The function sort sorts a vector in increasing order. We can therefore see the largest number of gun murders by t...
3296 sym R (2050 sym/27 pcs)
STAT3000 082824
Subsetting Difference to other programs, R starts from 1 not 0. You will find the index of first element of vector in Python is 0. This is key difference. Subsetting vector by index c1 = c(1:10) c1[1] ## [1] 1 c1[2] ## [1] 2 c1[1:2] ## [1] 1 2 c1[c(1:2,5)] ## [1] 1 2 5 tail(c1,5) ## [1] 6 7 8 9 10 head(c1,2) ## [1] 1 2 by negative index c...
2089 sym
STAT3000 082624
Recap What is the sum of the first 100 positive integers? The formula for the sum of integers 1 through n is $n(n+1)/2. Define \(n=100\) and then use R to compute the sum of 1 through 100 using the formula. What is the sum? Now use the same formula to compute the sum of the integers from 1 through 1,000. Look at the result of typing the followi...
3871 sym
STAT3000 082124
Variables Suppose a high school student asks us for help solving several quadratic equations of the form \(ax^2+bx+c=0\). The quadratic formula gives us the solutions: \(\frac{-b\pm\sqrt(b^2-4ac))}{2a}\), which of course change depending on the values of a, b, and c. We will write out general code for the quadratic equation below, but if we a...
6095 sym
STAT3000 0821/24
Variables Suppose a high school student asks us for help solving several quadratic equations of the form \(ax^2+bx+c=0\). The quadratic formula gives us the solutions: \(\frac{-b\pm\sqrt(b^2-4ac))}{2a}\), which of course change depending on the values of a, b, and c. We will write out general code for the quadratic equation below, but if we a...
4990 sym
STAT3000 081924
R Markdown This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com. When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within...
680 sym R (1069 sym/30 pcs) 2 img