How to use R-Studio In R
Here we are going to import data through R studio with the following steps.
Steps:
- From the Environment tab click on the Import Dataset Menu.
- Select the file extension from the option.
- In the third step, a pop-up box will appear, either enter the file name or browse the desktop.
- The selected file will be displayed on a new window with its dimensions.
- In order to see the output on the console, type the filename.
Read JSON Files Into R
In order to work with JSON files in R, one needs to install the “rjson” package. The most common tasks done using JSON files under rjson packages are as follows:
- Install and load the rjson package in R console
- Create a JSON file
- Reading data from JSON file
- Write into JSON file
- Converting the JSON data into Dataframes
- Working with URLs
JSON file for demonstration:
{ "ID":["1","2","3","4","5"], "Name":["Mithuna","Tanushree","Parnasha","Arjun","Pankaj"], "Salary":["722.5","815.2","1611","2829","843.25"], "StartDate":["6/17/2014","1/1/2012","11/15/2014","9/23/2013","5/21/2013"], "Dept":["IT","IT","HR","Operations","Finance"] }
Code:
R
# Read a JSON file # Load the package required to read JSON files. library ( "rjson" ) # Give the input file name to the function. result <- fromJSON (file = "E:\\example.json" ) # Print the result. print (result) |
Output:
$ID [1] "1" "2" "3" "4" "5" $Name [1] "Mithuna" "Tanushree" "Parnasha" "Arjun" "Pankaj" $Salary [1] "722.5" "815.2" "1611" "2829" "843.25" $StartDate [1] "6/17/2014" "1/1/2012" "11/15/2014" "9/23/2013" "5/21/2013" $Dept [1] "IT" "IT" "HR" "Operations" "Finance"
Importing Data in R Script
We can read external datasets and operate with them in our R environment by importing data into an R script. R offers a number of functions for importing data from various file formats.
In this article, we are going to see how to Import data in R Programming Language.
Contact Us