Data

telo.control <- c(0.95, 0.96, 1.07, 1.08, 1.09, 
             1.1,  1.12, 1.14, 1.18, 1.19, 
             1.19, 1.2, 1.34, 1.45,  1.49, 
             1.55)

telo.disturbed <- c(0.83, 0.84, 0.87, 0.93, 0.94, 
               0.96, 0.99, 1.00, 1.01, 1.01, 
               1.02, 1.05, 1.07, 1.08, 1.09,
               1.09, 1.12, 1.13, 1.16, 1.24, 
               1.41)
               
cort.control <-c(6.32, 1.56,  8.61, 4.86, 3.32, 
                4.31,  1.84, 10.45, 1.47, 4.57, 
                1.95,  5.93,  8.89, 1.16,   NA,
                  NA)

cort.disturbed <- c(7.38,  5.39, 5.39, 5.73, 18.35, 
                    0.95,  1.72, 7.26, 1.38,  4.22, 
                    7.52, 12.52, 3.86, 3.12,  1.36, 
                    2.26,  0.85, 4.76, 0.95,  6.92, 
                    2.16)
sex.cntrl <- c("F","M","F","F","F","F","F","M","F","F","M","F","M","M",
               "F","F")       
               
sex.dist <-  c("M", "M", "F", "F", "F", "M", "F", "M", "F", "M", "F",
                "F", "M", "F", "M", "M", "F", "M", "F", "M", "M")

##Example Functions

# prints out telo.control
telo.control
##  [1] 0.95 0.96 1.07 1.08 1.09 1.10 1.12 1.14 1.18 1.19 1.19 1.20 1.34 1.45 1.49
## [16] 1.55
# tells you what type of data structure telo.control is
is(telo.control)
## [1] "numeric" "vector"
# returns a boolean value confirming whether or not telo.control is a vector
is.vector(telo.control)
## [1] TRUE
# returns boolean of whether or not telo.control is a dataframe
is.data.frame(telo.control)
## [1] FALSE
# returns number of elements in telo.control
length(telo.control)
## [1] 16

R Markdown

Acts like a wordprocessor

hist(telo.disturbed)

boxplot(telo.control)

R as a Calculator/Statistics

mean(telo.disturbed)
## [1] 1.04
median(telo.control)
## [1] 1.16
max(telo.control)
## [1] 1.55
min(telo.disturbed)
## [1] 0.83
summary(telo.disturbed)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    0.83    0.96    1.02    1.04    1.09    1.41

Making Dataframes

telomeres <- c(telo.control, telo.disturbed)
sex <- c(sex.cntrl, sex.dist)
length(sex) == length(telomeres)
## [1] TRUE
df <- data.frame(telomeres, sex)

#returns number of rows in df
nrow(df)
## [1] 37
#returns number of columns in df
ncol(df)
## [1] 2
#shows you top of the dataframe
head(df)
##   telomeres sex
## 1      0.95   F
## 2      0.96   M
## 3      1.07   F
## 4      1.08   F
## 5      1.09   F
## 6      1.10   F
#shows you the bottom of the dataframe
tail(df)
##    telomeres sex
## 32      1.09   M
## 33      1.12   F
## 34      1.13   M
## 35      1.16   F
## 36      1.24   M
## 37      1.41   M
boxplot(telomeres ~ sex, data = df)

length(telo.control)
## [1] 16
trt.C <- rep("C", 16)
trt.D <- rep("D", 21)

trt.both <- paste(trt.C, trt.D)
trt.both
##  [1] "C D" "C D" "C D" "C D" "C D" "C D" "C D" "C D" "C D" "C D" "C D" "C D"
## [13] "C D" "C D" "C D" "C D" "C D" "C D" "C D" "C D" "C D"