import | R Documentation |
This function is a shotcut for the following functions: read.table
, read.csv
, read.spss
,
read_excel
import(file=NULL, dir=NULL, type=NULL, header=T, info=TRUE, dec=".",
sep=";",na.strings="NA",sheet=NULL, name="dataset")
file |
Character. Name of the file to import |
dir |
Character. Directory in which the file is stored |
type |
Type of file. One among "csv", "txt", "excel", "SPSS" |
header |
Logical. Is the name of the variables on the first row ? |
info |
Should information about dialog boxes be printed in the console? |
dec |
Character. The character used in the file for decimal points. |
sep |
The field separator character. Values on each line of the file are separated by this character. |
na.strings |
a character vector of strings which are to be interpreted as NA values. Blank fields are also considered to be missing values in logical, integer, numeric |
sheet |
Character. The name of the sheet for excel files. |
name |
Character. Name of the R object in which to store the data. |
The function imports data from text files, csv files, SPSS files and excel files. The function check variable names and correct them if necessary. Moreover, variable names are too long (> 30 characters), a dialog box suggest to shorten them. The function allows to deal accented letters in directory name and/or in file name.
The data frame is stored in R memory with the name given. The function also returns the structure of the data frame, the number of missing values for each variable when some values are missing.
Nicolas Stefaniak
# use with dialog box
import()
# use by command line
# create a csv file
write.csv2(cars, "cars.csv")
dir<-getwd()
# import the file
import(file="cars.csv",dir=dir,Type='csv',dec=',',sep=';',na.strings='NA',sheet=NULL,name="ez.cars")
# remove the file from directory
file.remove("cars.csv")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.