cherrypi / Science-Fair_2019

Vernal Pond graphing and data, as well as data analysis.
1 stars 0 forks source link

Read your data into R #2

Closed VCF closed 5 years ago

VCF commented 5 years ago

You now need to get your CSV data into R. You'll do this with a function called read.table, which has a few "convenient variant" functions as well. These functions give you something called a data.frame, which (along with matrix and array data structures) is one of the main data workhorses in R. You can read about it here:

?read.table
?read.csv  ## This is probably the one you want
?read.csv2

You should start coding your analysis script as you read about this. Start a script called analysis.R or something similar. The name is not too important, but someone else (including you 13 years from now, after you've forgotten what you've done) should be able to get a general idea of what the script is doing from the name. Make that file, and add code to read your CSV file. Remember that you want to read it into a variable. Like the file name, pick a variable name that is at least mildly meaningful.

cherrypi commented 5 years ago

You said something about "source", what was it?

VCF commented 5 years ago

The source() command is a way to run an R file in the R terminal. That is, if you had a file called countHippos.R, you could run it by opening an R session and calling source("countHippos.R"). See ?source.

VCF commented 5 years ago

Ok, so in caf621b you're loading the file correctly, but you're not "doing anything" with it. R will load your data, then just "throw it away". You need to capture it in a variable. Like most languages, you can do this with the = operator:

x = 2 + 2

... but R has a quirky "left get" operator "<-" that is often used - I advise that you use this, since your code will be more obviously "R-like":

x <- 2 + 2

Also, you should think of a more informative name that "x" for the variable to hold your data. After you've made the change, source() the file then use ls() to look in your "session" (the current R state) to see if the variable is there. If it is, you can use a very handy tool called str() to explore the STRuctrure of the variable.

VCF commented 5 years ago

Ok, 486c8c0 is mostly working. I am seeing issues with the data now that I look closer. Let's open a new issue to address them.