 Hi everyone, it's MJ and welcome back to this course on R. In this video, we're gonna be looking at importing and exporting data. But let's maybe take a step back and ask ourselves why we wanna import data and then we're gonna go to our studio and walk through the following steps. But let's start with this why. And I guess in order to have wisdom, which is what we all kinda wanna attain, one requires knowledge. But in order to have knowledge, one requires information. And in order to have information, one requires data. And in order to have data, one requires observations. So after observing something, you can generate data. But you then need to analyze this data in order to turn it into information. And we see that both data science and statistics are focused on this activity, the transforming of data into information. And what we're gonna see is that R is a powerful tool that can assist us with this transformation process. But first, we need to get our data into R. So let's look at how to import data. And this can be done following the following steps. First, you wanna open up any spreadsheet software. This can be Excel or Google Sheets. You then wanna create a sample by variable format. And what this means is that your columns contain variables and your rows contain the observations. And then something about R is that if you've got a missing value or you've got zeros or you've got some nulls, you wanna do an edit, find and replace all and change it to NA in capitals to represent the missing values. Another thing about R, you wanna avoid names using symbols. R does not like that. And then you can download it as a .csv file. Actually R supports a whole wide range of formats. But once you've done that, we can then go to RStudio. We click import data sets in environmental panel. We then tick the options we want. We can then view the data set and see a plot. We can manipulate the data set. That's like the primary purpose of R. And then afterwards we can export the data set with the following line. Just writing it to the CSV file, the data set, and then the new name of the file. But we're gonna go to RStudio now and walk through these steps together. So what you wanna do is open up some spreadsheet software and in your columns you wanna create some variables. So let's say we have height and weight. That's gonna be contained in the first two columns. And then in the rows we're going to put in our data. So let's just say 200, 300, 450, 50, and 10. And then what we'll have with the weight is just putting in some random data over here. And what we can then do is once we've typed in our data or you've copied it in from somewhere else, you wanna then go file download as a comma separated value. So we then click that. Remember I've saved mine as MJ data for R and it's then gonna pop up over there. What I then wanna do is come to RStudio. In RStudio, the top right-hand corner, I'm gonna click import data set. So I click import data set from text and I'm then going to choose this one that I've made over here, which is MJ data. Now what we'll see is this little menu here where we can change a few of the parameters. The big one is that if I had chosen no with the headings, then it's gonna put height and weight as observations, which we don't want, because they're gonna have V1 and V2 as the variables where we'd rather wanna use the headings and that way R knows that height is the name of the first variable, weight is the name of the second variable and the rest of that data is the observations. Now seeing that everything else looks fine, maybe one thing I wanna just take away is that dot, dot, dot sheet, which comes if you're using Google Sheets. And then what I'm gonna do is click import. Now when I click import, I'm gonna get it here in my top left-hand corner and there's some fun things you can do like you can order the things around depending on which variable you want and we can also see that in the top right-hand corner, we're gonna see that MJ data for R is going to be an object and it tells us how many variables and how many observations there are. So once we've done that, we can also plot our data just to see what it's all about. So let's play plot MJ data for R and sometimes we'll just pop up there. We click enter and we've got a lovely little graph. So what we've done is we've imported data into R, we'd normally use some manipulation or we plot it as a graph. And then once we've transformed the data, we can then also come and we can write it back to a CSV file and it's simple as saying MJ data two. And we can say file, sorry, what we wanna do here is give this the proper name, so MJ data for R and then when we click file equals, this is going to be the new name. So let's call it MJ data two. And then we hit enter and it's gonna have written the CSV file. And now if I wanna find that file, I simply come to Spotlight on Mac or whatever the equivalent is in Windows and we will see that the file has been created. We can show it and find our open it but it'll be exactly the same as the one that we've inputted because we haven't manipulated any of the data in this video. Later on in the course, we are gonna play around with transformation and manipulation, but yeah, in this video, we've just shown how easy it is to import data and then export data from Excel into R and then out of R back into a text file which can then again be manipulated in Excel again. Anyway, thanks so much for watching and I'll see you in the next video.