R Data Importing

Data Importing

  • R can read data from external files, stored outside the R environment
  • R has the capability to work with data in any format, such as csv, xlsx, json etc…
  • Steps to read a file are as follows:
    • Step 1: Set the path of the location to the file’s location
    • getwd() # gives the current directory
    • setwd(“path”) # sets the path, e.g.setwd(“D:/R/dataset/”)
    • Step 2: Ensure the relevant package is installed
    • library () # shows the packages that are loaded
    • for xlsx and json additional packages must be installed
    • Step 3: Use ‘read’ command to assign data to an object
    • read.csv () # reads the .csv file
    • read.xlsx () # reads the .xlsx file
    • read.table() # reads the .txt file

If we need to upload the file ‘Truck’ from “d:/R/” location

Data Importing in r language

Step 1: Set the path

Syntax
setwd("d:/R/")

Step 2: Ensure xlsx package is installed

xlsx package in r language

Step 3: Use read.xlsx() from xlsx package

Syntax
tk <- read.xlsx(file = "truck.xlsx", sheetName = "Sheet1")
#Data_Importing_r_language #r_programming_read_excel_file #r_language_read_excel

(New page will open, for Comment)

Not yet commented...