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
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
mySample <- rnorm(100, mean = 20, sd = 4)
se <- function(x) { v <- var(x) n <- length(x)
return(sqrt(v/n)) }
result <- se(mySample)
print(result)
set.seed(3) rnorm(10)
convertFtoC <- function(fahrenheit) { celsius <- (5/9) * (fahrenheit - 32) return(celsius) }
FT <- 68 celsiusTemperature <- convertFtoC(FT) print(paste(FT,“F is equal to”, celsiusTemperature, “C”))
convertFtoC <- function(fahrenheit) { celsius <- (5/9) * (fahrenheit - 32) return(celsius) }
FT <- c(12,76,78,100) celsiusTemperature <- convertFtoC(FT) print(paste(FT,“F is equal to”, celsiusTemperature, “C”))
gInfo <- c(“Male”, “Male”, “Male”, “Male”, “Male”)
gender <- factor(gInfo, levels = c(“Male”, “Female”))
print(gender)
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)
print(t)
margin.table(t, 1)
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
my.dataset\(season <- as.factor(my.dataset\)season) my.dataset\(site <- as.factor(my.dataset\)site)
print(my.dataset$pH)
print(my.dataset[my.dataset$pH > 7, ])
print(my.dataset\(ph[my.dataset\)site == “A”])
print(my.dataset[my.dataset$season == “Summer”, c(“site”, “ph”)])
my.dataset$NO3 <- c(234.5, 256.6, 654.1, 356.7, 776.4)
print(dim(my.dataset))