Importing a .csv file to R Studio using the read.csv function

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
we're going to try this again my audio wasn't working in my last upload for whatever reason today we're going to talk about importing data the correct way to are so I'm going to go ahead and open up our studio first thing you're going to notice here is that we have a cursor that is blinking in our console this is going to show up in the bottom left part of our studio you can type code directly into the command line hit return and R is going to do whatever you tell it to do now sometimes I mess up when I'm writing code and I also like to have control over saving the code that I write and maybe write myself some notes that is where the script editor comes in you can see that I'm using the hashtag-- line typing in the code selecting the line hitting run and it's going to pop down to the console next thing I need to do is choose my working directory this is really the first thing you need to do every time you open up our studio I'm going to select the folder in my case that's called our underscore examples and open that and you're gonna see down here in the console that it has set the working directory that means all the files I'm going to use today are in there so going back to our script editor again the nice thing here is that you can write yourself notes using the hashtag sign before we actually import our data I want us to take a look at the file that we're going to import it's called serial CSV and you can see here there are five columns of data we've got both categorical data as well as numerical data I'm going to make this a little bigger so we can look at it together there we go so one thing you're going to notice is that there are no special characters and there are no spaces anywhere in this data set if I were to for example leave this as fruit space loops instead of fruit underscore loops there is a strong possibility that our or our studio would get confused the next thing we need to do is make sure that it is saved in the right format which is comma separated value CSV I'm going to click say you're gonna come up with some potential error messages just go ahead and select yes all right so now our dataset is in the correct form and we can get it into our so now I'm going to go up to our script editors write myself a note that says import your data and the next line of code is going to essentially tell us how to do that so first and foremost we need to give our dataset a name that is going to show up over here in our global environment now we can call this data set whatever we want we might want to call it breakfast we might want to call it be fast for shorts we might want to call it bananas we can call it whatever we want the important thing here is that you give it a short and descriptive name again you can name your data sets your variables whatever you wants as long as you can remember what they're there for so everything essentially be fast the little arrow says that everything to the right is going to be named be fast so the code that we're gonna type in to the right of that little arrow is essentially the code to import a data set and name it be fast so I'm going to you through use the read CSV function and you can see some notes here about how to correctly use that function pop up so the first thing we need to do is open up a parenthesis as well as quotations and write in the name of our file so our file was called serials dot CSV then outside of the quotations we put a comma and right header equals true now what does this mean well if we hop back over to what our data looks like in Excel you can see that the first row is a header it gives the name of the data that is in each column so for example under cereal we have the name of each of the cereals so that tells our that the first line the first row of your data has information about the variable names next we put in Sep quotations , and this is because we saved our data as a comma-separated value you see under the save as menu in Excel that there are actually many different file types such as tab delimited again of course our comma separated there's even a space delimited text depending on what format you save your data set as you're going to need to change the step equation see there's no red that means everything went in okay so what does this look like in our we have this new be fast data set that is based on our serial CSV data set what does that look like we can type in B fast hit run and it returns what our data looks like we can also just double click on B fast over in the global environment and you can see we successfully got our data set into R looks pretty much exactly the same as a dozen Excel and that pretty much finishes up this very first part of our intro our lesson for today we will come back next time and talk about how to do some basic descriptive statistics as well as how to save the script that we are writing in the upper left-hand quadrant of our our Studio platform
Info
Channel: Charlene McCord
Views: 70,662
Rating: 4.8730903 out of 5
Keywords: CSUDH, Biostats, BIO 502, R Studio, importing data
Id: oRaPjJefoTo
Channel Id: undefined
Length: 5min 56sec (356 seconds)
Published: Sun Nov 10 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.