项目作者: maurolepore

项目描述 :
Load external data from a .csv file into a data frame (5' training for The Carpentries)
高级语言:
项目地址: git://github.com/maurolepore/loaddata.git
创建时间: 2018-04-02T20:54:03Z
项目社区:https://github.com/maurolepore/loaddata

开源协议:

下载


Load external data from a .csv file into a data frame


See https://bit.ly/carpentry-slides

Try by intuition

Document what you did.

  1. # Some code goes here

Back to the lesson

To download the data into the data/ subdirectory, run the following:

WARNING: This will fail. Why? (Run and read the error message)

Hint: * Look in the Files tab. What’s missing? * What are the first two arguments of download.file()? * Find out with the help of autocompletion (press TAB) or with ?

  1. # MISTERY-FUNCTION-GOES-HERE("data")
  2. download.file(
  3. "https://ndownloader.figshare.com/files/2292169",
  4. "data/portal_data_joined.csv"
  5. )
  6. #> Warning in download.file("https://ndownloader.figshare.com/files/
  7. #> 2292169", : URL https://ndownloader.figshare.com/files/2292169: cannot open
  8. #> destfile 'data/portal_data_joined.csv', reason 'No such file or directory'
  9. #> Warning in download.file("https://ndownloader.figshare.com/files/
  10. #> 2292169", : download had nonzero exit status

You are now ready to load the data:

  1. surveys <- read.csv("data/portal_data_joined.csv")

Print the variable’s value: surveys

  1. # WARNING: In the console, this prints looooong output
  2. surveys

Let’s check the top (the first 6 lines) of this data frame using the function head():

  1. head(surveys)
  2. #> record_id month day year plot_id species_id sex hindfoot_length weight
  3. #> 1 1 7 16 1977 2 NL M 32 NA
  4. #> 2 72 8 19 1977 2 NL M 31 NA
  5. #> 3 224 9 13 1977 2 NL NA NA
  6. #> 4 266 10 16 1977 2 NL NA NA
  7. #> 5 349 11 12 1977 2 NL NA NA
  8. #> 6 363 11 12 1977 2 NL NA NA
  9. #> genus species taxa plot_type
  10. #> 1 Neotoma albigula Rodent Control
  11. #> 2 Neotoma albigula Rodent Control
  12. #> 3 Neotoma albigula Rodent Control
  13. #> 4 Neotoma albigula Rodent Control
  14. #> 5 Neotoma albigula Rodent Control
  15. #> 6 Neotoma albigula Rodent Control

Thank you