diff options
Diffstat (limited to 'r.html.markdown')
| -rw-r--r-- | r.html.markdown | 21 | 
1 files changed, 15 insertions, 6 deletions
| diff --git a/r.html.markdown b/r.html.markdown index b59fc29c..d3d725d3 100644 --- a/r.html.markdown +++ b/r.html.markdown @@ -8,7 +8,7 @@ filename: learnr.r  R is a statistical computing language. It has lots of libraries for uploading and cleaning data sets, running statistical procedures, and making graphs. You can also run `R` commands within a LaTeX document. -```python +```r  # Comments start with number symbols. @@ -179,7 +179,7 @@ c(3,3,3,2,2,1) # 3 3 3 2 2 1  # You can also have infinitely large or small numbers  class(Inf)	# "numeric"  class(-Inf)	# "numeric" -# You might use "Inf", for example, in integrate( dnorm(x), 3, Inf); +# You might use "Inf", for example, in integrate(dnorm, 3, Inf);  # this obviates Z-score tables.  # BASIC ARITHMETIC @@ -229,6 +229,13 @@ FALSE != FALSE	# FALSE  FALSE != TRUE	# TRUE  # Missing data (NA) is logical, too  class(NA)	# "logical" +# Use | and & for logic operations. +# OR +TRUE | FALSE	# TRUE +# AND +TRUE & FALSE	# FALSE +# You can test if x is TRUE +isTRUE(TRUE)	# TRUE  # Here we get a logical vector with many elements:  c('Z', 'o', 'r', 'r', 'o') == "Zorro" # FALSE FALSE FALSE FALSE FALSE  c('Z', 'o', 'r', 'r', 'o') == "Z" # TRUE FALSE FALSE FALSE FALSE @@ -236,11 +243,12 @@ c('Z', 'o', 'r', 'r', 'o') == "Z" # TRUE FALSE FALSE FALSE FALSE  # FACTORS  # The factor class is for categorical data  # Factors can be ordered (like childrens' grade levels) or unordered (like gender) -factor(c("female", "female", "male", "NA", "female")) -#  female female male   NA     female -# Levels: female male NA +factor(c("female", "female", "male", NA, "female")) +#  female female male   <NA>   female +# Levels: female male  # The "levels" are the values the categorical data can take -levels(factor(c("male", "male", "female", "NA", "female"))) # "female" "male"   "NA"  +# Note that missing data does not enter the levels +levels(factor(c("male", "male", "female", NA, "female"))) # "female" "male"  # If a factor vector has length 1, its levels will have length 1, too  length(factor("male")) # 1  length(levels(factor("male"))) # 1 @@ -251,6 +259,7 @@ levels(infert$education) # "0-5yrs"  "6-11yrs" "12+ yrs"  # NULL  # "NULL" is a weird one; use it to "blank out" a vector  class(NULL)	# NULL +parakeet = c("beak", "feathers", "wings", "eyes")  parakeet  # =>  # [1] "beak"     "feathers" "wings"    "eyes"     | 
