Closed VCF closed 5 years ago
You said something about "source", what was it?
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
.
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.
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.
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 adata.frame
, which (along withmatrix
andarray
data structures) is one of the main data workhorses in R. You can read about it here: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.