Worksheet 18: reading Excel files and some ant data. Reading Excel files can be done in two ways in R.

Method 1: Save your Excel spreadsheet as a .csv file and use read.csv() function. Method 2: use the read.xls2() function from the xlsx library.

Task 1:c Download the file CompleteGeneticData.xlsx from iLearn. Save the excel file CompleteGeneticData.xlsx as a .csv file Create a new .RMD file. Save it with a reasonable name in the same folder as CompleteGeneticData.xlsx

Read it into R, using the read.csv() function and save the resulting object with a reasonable name.

Task 2: Install the xlsx package and read the CompleteGeneticData.xlsx into R, save the resulting object with a reasonable name.

#read.csv("CompleteGeneticData1.csv")->csvcomgen
#install.packages("xlsx")
#library(xlsx)
#read.xlsx2("CompleteGeneticData.xlsx",1)->xlsxcomgen

Task 3: Use summary() and head() to look at the objects you created. Also click on the object in the upper right panel of Rstudio to look at the data.frame in the upper left panel.

#head(csvcomgen)
#head(xlsxcomgen)

Task 4 The columns with strange names (e.g., GT218) hold genotypes from microsattelite loci. Look up microsattelite using google, and write down what it is. #Microsattelites are tadem repeats of 2-5 bp

Task 5 Make a subset of the data for only the ants from plot “WV.R” (WV is West Viriginia).

Make a scatter plot to show the locations of the ant nests in plot WV.R using the transect.x and transect.y columns.

#subset data
#csvcomgen[csvcomgen$Plot=='WV.R', ]->WVR
#plot(WVR$transect.x, WVR$transect.y, main="Scatterplot Transect X vs.Y", xlab="Transect.x", ylab="Transect.y", col= "blue")

Task 6 Make a histogram of the microsattelite length for each of the microsatellite loci in the entire dataset.

for (i in 9:20){hist(WVR[,i],col=i, main=“Histogram of WVR microsatellite #lengths”, xlab= )}

Task 7 How many of the sampled ants are slaves?

#3066
#length(csvcomgen$free_slave)

Task 8 (bonus question) How many of the ant nests contain slaves? (for the last question, you can select the two columns that have the colony name and whether the ants are free and use the unique() function on those two columns) E.g., unique(DATA[,c(5,7)])

#install.packages("plyr")
#library(plyr)
#count(csvcomgen$free_slave)

Task 9: Knit your RMD file and publish the html file online, then upload the link to iLearn.