![]() ![]() You might come into a situation where you want to export your dataset to an Excel file. The only advantage of save() really is that you can save several objects into one file - but in the end it might be better to have one file for one object. Also, it is more similar to the behavior of all the other “reading functions” like read.table(): for these, you also have to assign the result to a variable. This might mean more typing but it also has the advantage that you can choose a new name for the variable to integrate it in into the rest of the new script more smoothly. When we use readRDS(), we have to assign the result of the reading process to a variable. But this also means that you have to “remember” the names of the previously used objects when using load(). When we use load(), we do not assign the result of the loading process to a variable because the original names of the objects are used. So, you might ask “why should I use saveRDS() instead of save()”? Actually, I like saveRDS() better - for one specific reason that you might not have noticed in the calls above. The difference between save() and saveRDS() In the scope of this post, let’s suppose that the calculation above took veeeery long and you absolutely don’t want to run it everytime. If they don’t, you can just run your pre-processing code every time you are getting back to analyzing the dataset. data$ <- is.na(data$gender) | data$gender = "Unknown"Īs I wrote above: Saving the current state of your dataset in R makes sense when all the preparations take a lot of time. Here, I’m assigning a new column data$ which is TRUE whenever data$gender is "Unknown" or NA. Just for the sake of simulating a real workflow, I will do some very light data manipulation. If that’s the case, you may want to visit the following guide that explains how to import a CSV file into R.įinally, you may also want to check the Data Output documentation.We now have a dataset with over 50,000 rows (you can scroll through the first 6 of them in the box above) and 14 variables in our global environment (the ‘workspace’). At times, you may face an opposite situation, where you’ll need to import a CSV file into R. You just saw how to export a DataFrame to a CSV file in R. The data within that file should match with the data in DataFrame created in R: name ![]() By adding a double backslash, you would avoid the following error in R:Įrror: ‘\U’ used without hex digits in character string starting “”C:\U” Step 3: Run the code to Export the DataFrame to CSVįinally, run the code in R (adjusted to your path), and a new CSV file will be created at your specified location. Don’t forget to add that portion when exporting CSV filesĪlso notice that a double backslash (‘\\’) was used within the path.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |