Data

#control
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)
#Experimental
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)
#control Cort               
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)
#experimental cort
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)
#W chromosome to determine sex
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")
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 us what data type this is

is(telo.control)
## [1] "numeric" "vector"
is.vector(telo.control)
## [1] TRUE
is.data.frame(telo.control)
## [1] FALSE
length(telo.control)
## [1] 16
length(telo.disturbed)
## [1] 21

##RMarkdown… essentially a word processor Just type into the white and it will just be text and you can just put the r in the grey in between the text

hist(telo.control)

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
hist(telo.control)

boxplot(telo.control)

#Making dataframes #each of these below is a vector and is part ot telo #c operator makes both of these individual operators into a single vector #we then place the combined data into a new thing called telomeres and now that contains the combined vector

telomeres <- c(telo.control , telo.disturbed)
telomeres
##  [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 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
## [31] 1.09 1.09 1.12 1.13 1.16 1.24 1.41
length(telomeres)
## [1] 37
is(telomeres)
## [1] "numeric" "vector"
is.vector(telomeres)
## [1] TRUE
is.data.frame(telomeres)
## [1] FALSE

#ls() lists everything in memory

ls()
## [1] "cort.control"   "cort.disturbed" "sex.cntrl"      "sex.dist"      
## [5] "telo.control"   "telo.disturbed" "telomeres"
sex.cntrl 
##  [1] "F" "M" "F" "F" "F" "F" "F" "M" "F" "F" "M" "F" "M" "M" "F" "F"
sex.dist
##  [1] "M" "M" "F" "F" "F" "M" "F" "M" "F" "M" "F" "F" "M" "F" "M" "M" "F" "M" "F"
## [20] "M" "M"
is(sex.cntrl)
## [1] "character"           "vector"              "data.frameRowLabels"
## [4] "SuperClassMethod"
is.vector(sex.cntrl)
## [1] TRUE
sex <- c(sex.cntrl , sex.dist)
sex 
##  [1] "F" "M" "F" "F" "F" "F" "F" "M" "F" "F" "M" "F" "M" "M" "F" "F" "M" "M" "F"
## [20] "F" "F" "M" "F" "M" "F" "M" "F" "F" "M" "F" "M" "M" "F" "M" "F" "M" "M"
length(sex.cntrl) + length(sex.dist)
## [1] 37
length(sex)
## [1] 37
length(telomeres) == length(sex)
## [1] TRUE
telomeres 
##  [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 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
## [31] 1.09 1.09 1.12 1.13 1.16 1.24 1.41
sex
##  [1] "F" "M" "F" "F" "F" "F" "F" "M" "F" "F" "M" "F" "M" "M" "F" "F" "M" "M" "F"
## [20] "F" "F" "M" "F" "M" "F" "M" "F" "F" "M" "F" "M" "M" "F" "M" "F" "M" "M"

#must test to make sure that both sides are equal to make aa data frame

df <- data.frame(telomeres,sex)
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
## 7       1.12   F
## 8       1.14   M
## 9       1.18   F
## 10      1.19   F
## 11      1.19   M
## 12      1.20   F
## 13      1.34   M
## 14      1.45   M
## 15      1.49   F
## 16      1.55   F
## 17      0.83   M
## 18      0.84   M
## 19      0.87   F
## 20      0.93   F
## 21      0.94   F
## 22      0.96   M
## 23      0.99   F
## 24      1.00   M
## 25      1.01   F
## 26      1.01   M
## 27      1.02   F
## 28      1.05   F
## 29      1.07   M
## 30      1.08   F
## 31      1.09   M
## 32      1.09   M
## 33      1.12   F
## 34      1.13   M
## 35      1.16   F
## 36      1.24   M
## 37      1.41   M
is(df)
## [1] "data.frame" "list"       "oldClass"   "vector"
is.vector(df)
## [1] FALSE
is.data.frame(df)
## [1] TRUE
#dim command gives the dimensions of the "spreadsheet" that we just made 
dim(df)
## [1] 37  2
#length of data frame is # of columns
length(df)
## [1] 2
#data frames have diensions and length, vectors only have length 
#number of rows
nrow(df)
## [1] 37
#number of columns 
ncol(df)
## [1] 2
#shows head of data frame 
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 bottom of data frame 
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

#compare telomere sets by sex

#put y variable on the left, followed by tilda (~) and x variable on right 
#need to have data set up in data frames so boxplot(y ~ x, data = dataframe)
boxplot(telomeres ~ sex, data = df)

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