1. Selecting & uploading a file when prompted
This is the simplest and most preferable way to import a csv file. Why I’m saying it is most preferable because when we design an application and ask user to upload a file, we will provide a routine which will let the user to select & upload their desired file.
So, the syntax is:
read.csv(file.choose())
That’s it! Executing this line will provide a file upload prompt to the user and user can select the appropriate file as shown in below image:
But what if we want to store the data present in a file to some variable?
Here is the magic:
Previously we have created many vectors & matrices and stored them in a variable by writing the single line code.
In a similar way we can do this as well. Isn’t it a great feature?
Data1 <- read.csv(file.choose())
Executing above line will upload a file, extract the data and store it in a variable. Now you can count the Line of Code we have just written.