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 the document. You can embed an R code chunk like this:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

max(sample(1:100,30)) #print(sample(1:100,30))

#3 ?sample

#4

#sample takes a sample of the specified size from the elements of x using either with or without replacement. #5

Create a variable mySample with a random sample from a normal distribution

mySample <- rnorm(100, mean = 20, sd = 4)

Function se

se <- function(x) { v <- var(x) n <- length(x)
return(sqrt(v/n)) }

Call the function and pass mySample as an argument

result <- se(mySample)

Convert the Temperature from F to C

convertFtoC <- function(fahrenheit) { celsius <- (5/9) * (fahrenheit - 32) return(celsius) }

Example usage:

FT <- 68 celsiusTemperature <- convertFtoC(FT) print(paste(FT,“F is equal to”, celsiusTemperature, “C”))

Convert the Temperature from F to C using Vector

convertFtoC <- function(fahrenheit) { celsius <- (5/9) * (fahrenheit - 32) return(celsius) }

Example usage:

FT <- c(12,76,78,100) celsiusTemperature <- convertFtoC(FT) print(paste(FT,“F is equal to”, celsiusTemperature, “C”))

Create a vector with the sex information for five individuals (all male)

gInfo <- c(“Male”, “Male”, “Male”, “Male”, “Male”)

Create a factor object with specified levels

gender <- factor(gInfo, levels = c(“Male”, “Female”))

Create a factor with specified levels

a <- factor(c(‘adult’, ‘adult’, ‘juvenile’, ‘juvenile’, ‘adult’, ‘adult’, ‘juvenile’, ‘adult’, ‘juvenile’, ‘adult’)) g <- c(“Male”, “Female”, “Female”, “Female”, “Female”, “Female”,“Male”,“Male”,“Male”,“Male”) # Create a table using the factor ‘a’ t <- table(a,g)

Compute the margin table (row-wise)

margin.table(t, 1)

Create data frame

my.dataset <- data.frame ( site = c(‘A’,‘B’,‘A’,‘A’,‘B’), season = c(‘Winter’,‘Summer’,‘Summer’,‘Spring’,‘Fall’), ph = c(7.4,6.3, 8.66,7.2,8.9) ) # Display the data frame my.dataset # Display the element at position (3,2) Result<-my.dataset[c(3,2)] Result Result1<-my.dataset[c(3),c(2)] Result1

Coerce ‘season’ and ‘site’ columns into factors

my.dataset\(season <- as.factor(my.dataset\)season) my.dataset\(site <- as.factor(my.dataset\)site)

Access the attribute pH using $

print(my.dataset$pH)

Display all entries with pH > 7

print(my.dataset[my.dataset$pH > 7, ])

Display pH for site = “A”

print(my.dataset\(ph[my.dataset\)site == “A”])

Display site and pH for season = “Summer”

print(my.dataset[my.dataset$season == “Summer”, c(“site”, “ph”)])

Add a new column titled NO3

my.dataset$NO3 <- c(234.5, 256.6, 654.1, 356.7, 776.4)

Display the dimensions of the dataset

print(dim(my.dataset))