Learning R Ecology 180.docxWelcome to Learning R!This workshop is designed for folks with a wide range of previous experience in R, from completebeginners to experienced R-coders. The course is...

1 answer below »
i need to have this done or as much as possible today


Learning R Ecology 180.docx Welcome to Learning R! This workshop is designed for folks with a wide range of previous experience in R, from complete beginners to experienced R-coders. The course is organized around a series of assignments that you work on at home, with weekly meetings to troubleshoot and discuss issues that arise. Intro: What's Going On? R is a powerful, flexible, and dynamic language for scientific programming, plotting and statistical analysis. It is free and open-source and has a big community of users that are constantly developing new "packages" that increase the capability of the language. R is the software engine that runs our code. In R, code is written as a "script" - a series of commands that get fed to R one at a time. R Studio is an integrated development environment (IDE) for R. It is free software that provides a nicer environment for developing code. R Studio makes your code look better and provides convenient tools that make your code faster and easier to read and write. R Markdown is a kind of R script that is especially well-suited for collaborative data analysis. It makes it easier to write notes, integrate figures, and generate reports to share your analysis with others. Your normal R code is still readily available and accessible inside "code chunks". The tidyverse is a set of R packages that provide an alternative way to do many things in R, from data manipulation to plotting. When you install the tidyverse package, you are installing several component packages; key among them is ggplot2 (a plotting package) and dplyr (a data manipulation package). In comparison, "base R” is R using only the packages that come with a standard installation. We will use both. General Advice: We Can Work It Out 1. If you are new to R, challenge yourself to type in new commands instead of cutting and pasting. Typing forces you to learn the conventions of unfamiliar script, and to figure out which parts of the syntax are flexible and which are not. Once you are more familar with the syntax, you can start using copy/paste and other tricks to move faster. 2. Try taking apart long nested commands from the inside out. Break up the long command into manageable parts. Try to understand how the computer sees each part. 3. Embrace the struggle, but don’t worry to much if you get stuck. 4. Use the help (?) function often and learn how to read the documentation efficiently. 5. Use the internet. Even the pros use the internet to remember synatax, figure out the best approach and learn new tools. 6. Aim to write consistent and organized code with clear headings and consistent naming conventions. Provide enough expla.nation of your code so that others can understand what you did. 7. Make sure your script can run cleanly from the top down, without internal conflicts. 8. Be creative and brave. There are usually many ways to do the same thing in R. Look for ways that are efficient, clear and elegant. https://www.r-project.org/ https://www.rstudio.com/ https://rmarkdown.rstudio.com/ https://www.tidyverse.org/ Step 1: People Get Ready 1. Install R and RStudio. 2. Open RStudio. 3. Arrange RStudio so that you can see the console, environment, and help windows. 4. Go to Tools>Global Options>Appearance and choose an "Editor theme" that you'll want to stare at for several hours at a time. 5. Create a new R Markdown (Rmd) file. Title it something like “ Learning R”, add your name as the author, and set the output to HTML. This will open in a new window - the script window. 6. Create a folder with your name in the Google Drive “Learning R” folder. Save your Rmd file to this folder. 7. Knit and view your Rmd report. Your report should be an HTML file. Compare the report with the script. 8. Change the heading "R Markdown" to read "Step 1: People Get Ready" and re-knit. What happens? 9. Delete everything below your heading. 10. Insert a new R chunk below your heading. The boundaries of an R chunk are just text. Try to break the chunk and fix it again. 11. Type data() into the console and run it to view a list of example datasets. 12. Type ?data into the console to view a description of the data function in the help window. Inspect the help documentation closely; every function in R has its own help documentation in the same format. Try to understand what each section of this help documentation does. 13. Type the name of the dataset pressure into the console. 14. Type pressure$temperature into the console. What does the "$" symbol do? What would pressure$pressure return? 15. Type plot(pressure$temperature, pressure$pressure) into the console. 16. Type plot(pressure$temperature, pressure$pressure) into your new R chunk and run it. What is the difference between the console and the script windows? 17. Type ?plot into the console to view a description of the plot function. 18. What would the command plot(pressure$pressure, pressure$temperature) return? Make a prediction in your head before you run it in your chunk. 19. Plot some data from the datasets CO2 and chickwts the same way. 20. At this point, you should have several lines in your chunk. Figure out how to run one line at time ("Run Selected Line(s)"), how to run the entire current chunk ("Run Current Chunk"), and how to run the entire script ("Run All"). 21. Search for an R Markdown reference guide or cheatsheet online. 22. Write a short description of what you did/learned at the end of your Rmd file, after your chunk. Be sure to explain what the script, console, and help windows show. Also write a sentence that includes italics, bold, and a link to an interesting website about one of your hobbies. 23. When you close RStudio, be sure to save any changes to your Rmd, but don’t save your workspace. Step 2: The Way You Do The Things You Do 1. Open your Rmd in RStudio. 2. Create a new heading ("Step 2: The Way You Do The Things You Do") and make a new R chunk. 3. Type write.csv(pressure,file="pressure.csv") into the new Rmd chunk, then run it. 4. Look for the file “pressure.csv” in your folder. Open it in a spreadsheet program like Excel, then close it. 5. Type ?write.csv into the console. Read the description in your help window and try to understand what how the write.csv function works. 6. Type read.csv("pressure.csv") into your Rmd chunk below the write.csv command, then run the chunk again. What happened? 7. Edit your read.csv command to say d1<-read.csv("pressure.csv"), then="" run="" the="" chunk="" again.="" look="" in="" your="" environment="" window.="" what="" happened="" this="" time?="" 8.="" click="" on="" the="" "d1"="" in="" the="" environment="" window.="" 9.="" click="" on="" the="" small="" blue="" triangle="" to="" the="" left="" of="" the="" "d"="" in="" the="" *environment*="" window.="" 10.="" type="" d1="" into="" your="" chunk="" and="" run="" it.="" 11.="" type="" plot(d1$pressure,="" d1$temperature,="" col="blue" ,="" pch="2," type="b" ,="" cex="0.5)" into="" the="" chunk="" and="" run="" it.="" 12.="" read="" the="" help="" documentation="" for="" the="" base="" r="" plot="" function="" ("plot")="" and="" the="" graphical="" parameters="" function="" ("par").="" 13.="" search="" the="" internet="" for="" more="" information="" about="" graphical="" parameters="" and="" colors="" in="" r.="" 14.="" plot="" a="" new="" figure="" using="" a="" built-in="" dataset="" from="" data().="" make="" it="" colorful.="" 15.="" create="" a="" new,="" fake="" dataset="" in="" a="" csv="" spreadsheet="" (or="" use="" a="" real="" one="" of="" your="" own)="" and="" import="" it="" into="" r="" as="" "d2".="" 16.="" plot="" these="" data="" any="" way="" you="" want="" to.="" 17.="" any="" text="" preceded="" by="" a="" hashtag="" (“#”)="" inside="" of="" a="" chunk="" becomes="" a="" comment="" –="" a="" short="" human-readable="" note="" that="" is="" not="" evaluated="" by="" r.="" comments="" allow="" you="" to="" organize="" and="" explain="" your="" code="" better.="" add="" a="" few="" to="" your="" chunk.="" 18.="" run="" your="" entire="" script="" from="" the="" top="" (code=""> Run Region > Run All). 19. Write a short description of what you did/learned at the end of your Rmd file, after your chunk. 20. When you close RStudio, be sure to save any changes to your Rmd, but don’t save your workspace. Step 3: Starting All Over Again 1. Open your Rmd in RStudio. 2. Type install.packages("tidyverse") into the console and run it. 3. Type library(tidyverse) into the setup chunk of your Rmd. The setup chunk is the one labeled “{r setup, include=FALSE}” 4. While you are at it, make a new chunk just below your setup chunk. Label it {r clear workspace}, and add the two lines rm(list=ls()) and graphics.off() to this chunk. These lines will clear the workspace so that you have a clean slate whenever you run the entire script from the top. 5. Run your entire script from the top (Code > Run Region > Run All). 6. Create a new heading (“Step 3: Starting All Over Again”) at the bottom of your script and make a new chunk. 7. Type ggplot(cars, aes(x=speed, y=dist)) +geom_point() +geom_smooth(formula=y~x, method="lm") and run the chunk. 8. Type ggplot(chickwts, aes(x=feed, y=weight, fill=feed)) +geom_col() and run the chunk. 9. Type ggplot(iris, aes(x=Sepal.Length, y=Petal.Length, col=Species, group=Species)) +geom_point() +geom_smooth(formula=y~x, method="lm") and run the chunk. 10. Type ggplot(iris, aes(x=Sepal.Length, y=Petal.Length, col=Species, size=Petal.Width, group=Species)) +geom_point(alpha=0.5) +geom_smooth(formula=y~x, method="lm") +facet_wrap(~Species, nrow=1, scales="free") +theme(legend.position = "bottom") and run the chunk. 11. Notice how I put spaces after commas and before the plus sign? It helps with text wrapping. 12. Go to https://ggplot2.tidyverse.org/reference/index.html and figure out what you’ve done. 13. Add brief comments to your chunk before each ggplot() call. 14. Create another plot using a different dataset. You can use any combination of base R and ggplot. Try to make plots that are both information-rich and aesthetically compelling. 15. Write a short description of what you did/learned at the end of your Rmd file, after your chunk. 16. When you close RStudio, be sure to save any changes to your Rmd, but don’t save your workspace. Step 4: Can You Get To That 1. Open your Rmd in RStudio. 2. Run your entire script from the top (Code > Run Region > Run All). 3. Create a new heading (“Step 4: It’s Your Thing”) and make a new chunk. 4. Type a<-c(1,2,3,4) into="" the="" chunk="" and="" run="" it.="" (note="" your="" environment="" window.)="" 5.="" type="" a="" into="" the="" chunk="" and="" run="" it.="" 6.="" type=""><-c(5,6,7,8) into="" the="" chunk="" and="" run="" it.="" 7.="" type="" b="" into="" the="" chunk="" and="" run="" it.="" 8.="" type="" a*b="" into="" the="" chunk="" and="" run="" it.="" 9.="" type="" a+b="" into="" the="" chunk="" and="" run="" it.="" 10.="" type="" b[3]="" into="" the="" chunk="" and="" run="" it.="" 11.="" type="" b[1:3]="" into="" the="" chunk="" and="" run="" it.="" 12.="" type="" a[3]+b[3]="" into="" the="" chunk="" and="" run="" it.="" 13.="" type="" iris="" into="" the="" chunk="" and="" run="" it.="" 14.="" type="" head(iris)="" into="" the="" chunk="" and="" run="" it.="" 15.="" type="" tail(iris)="" into="" the="" chunk="" and="" run="" it.="" 16.="" type="" names(iris)="" into="" the="" chunk="" and="" run="" it.="" 17.="" type="" unique(iris$species)="" into="" the="" chunk="" and="" run="" it.="" 18.="" type="" iris[1,]="" into="" the="" chunk="" and="" run="" it.="" 19.="" type="" iris[,1]="" into="" the="" chunk="" and="" run="" it.="" 20.="" type="" iris[1:10,1]="" into="" the="" chunk="" and="" run="" it.="" 21.="" type="" iris[1:10,"petal.length"]="" into="" the="" chunk="" and="" run="" it.="" 22.="" type="" iris[,"petal.length"]="" into="" the="" chunk="" and="" run="" it.="" 23.="" type="" iris[,"sepal.length"]="" into="" the="" chunk="" and="" run="" it.="" 24.="" type="" iris[,c("petal.length","sepal.length")]="" into="" the="" chunk="" and="" run="" it.="" 25.="" type="" iris[which(iris$species="="versicolor"),]" into="" the="" chunk="" and="" run="" it.="" 26.="" type="" iris[which(iris$species="="versicolor"" &="" iris$petal.length="">4.8),] into the chunk and run it. 27. Type iris[which(iris$Petal.Length==max(iris$Petal.Length)),] into the chunk and run it. 28. Read the help documentation on the which() function. 29. Type iris %>% filter(Species=="versicolor" & Petal.Length>4.8) into the chunk and run it. 30. Type iris %>% filter(Petal.Length==max(Petal.Length)) into the chunk and run it. 31. Type iris %>% mutate(Petal.Ratio=Petal.Length/Petal.Width, Sepal.Ratio=Sepal.Length/Sepal.Width) into the chunk and run it. 32. Go to https://dplyr.tidyverse.org/and figure out what you’ve done. 33. Write a short description of what you did/learned at the end of your Rmd file, after your chunk. What does the “%>%” operator do in dplyr? 34. When you close RStudio, be sure to save any changes to your Rmd, but don’t save your workspace. Step 5: It’s Your Thing 1. Open your Rmd in RStudio. 2. Run your entire script from the top (Code > Run Region > Run All). 3. Create a new heading (“Step 5: It’s Your Thing”) and make a new chunk. 4. Type aggregate(Petal.Length ~ Species, data=iris, FUN="mean") into the chunk and run it. 5. Type aggregate(weight ~ feed, data=chickwts, FUN="mean") into the chunk and run it. 6. Read the help documentation on the aggregate() function. 7. Type iris %>% group_by(Species) %>% summarize(mean=mean(Petal.Length),
Answered Same DayMar 22, 2023

Answer To: Learning R Ecology 180.docxWelcome to Learning R!This workshop is designed for folks with a wide...

Divya V answered on Mar 22 2023
43 Votes
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here