Learn R Programming

car (version 3.1-5)

Import: Import data from many file formats

Description

Uses the import function from the rio package to read a data.frame from a variety of file types. The Import function includes 2 additional arguments adding row names and for converting character and logical variables to factors for some file types.

Usage

Import(file, format, ..., row.names=TRUE,
       stringsAsFactors = FALSE)

Arguments

Value

A data frame. See import for more details

Details

This function calls the import function to read a data frame from a file. Many file types are supported. For files of type "txt", "csv", "xlsx", "xls" or "ods" the arguments row.names and stringsAsFactors can be used to add row names and convert character variables to factors, respectively. Many more details are given on the man page for import.

See Also

import, Export, strings2factors

Examples

Run this code
if(require("rio")) {

head(Duncan, 3) # first three rows
Export(Duncan, "Duncan.csv", keep.row.names="occupation")
Duncan2 <- Import("Duncan.csv") # Automatically restores row.names and factors
brief(Duncan2) 
identical(Duncan, Duncan2) # FALSE because type is of a different class
Duncan3 <- Import("Duncan.csv", stringsAsFactors=TRUE) 
brief(Duncan3) 
identical(Duncan, Duncan3) # TRUE type is of same class
# cleanup
unlink("Duncan.csv")

}

Run the code above in your browser using DataLab