In the Win32 bit system, the function inside the RODBC package can be run directly, but the Win64 bit system is not supported!
1. Read external file read.table ()---csv,txt,excel
The basic function is read.table (), first introduce read.table (), and then introduce the read.csv () that is specifically used to read the CSV.
Description
Reads a file in table format and creates a data frame from it, with cases corresponding to lines and variables to fields I n the file.
Read a file in tabular form and create a corresponding data frame, while preserving the corresponding variables and observations.
Usage
Read.table (file, Header = FALSE, Sep = "", quote = "\" ", Dec =". ", numerals = C (" Allow.loss "," Warn.loss "," No.loss "), R Ow.names, col.names, as.is =!stringsasfactors,
na.strings = "NA", colclasses = na, nrows =-1, skip = 0, Check.names = TRUE, fill =!blank.lines.skip, Strip.white = Fals E, Blank.lines.skip = TRUE, Comment.char = "#",
Allowescapes = false, flush = false, Stringsasfactors = Default.stringsasfactors (), fileencoding = "", encoding = "Unknown ", text, Skipnul = FALSE)
But there are only a few parameters that are commonly used, rewritten as follows:
read.table (file, Header = False, Sep = "", quote = "\" ", Dec =". ", skip = 0, Strip.white = false, Blank.lines.skip = TRUE, Comment.char = "#")①file represents the file to be read. File can be either an absolute path or a relative path, but it is important to note that because
\ is an escape character in the R language, the path delimiter must be written as \ \, such as "C:\\myfile\\myfile.csv".② can use the contents of the Clipboard, can be used to read the Excel format of the file, the data will be read to copy, and then enter data=read.table ("clipboard", T) in R.③ uses File.choose () to pop up a dialog box that lets you select a file location. It is
highly recommended to use this method, eliminating the hassle of remembering and writing file paths, especially to avoid errors caused by data File location movement! For example: Read.table (File.choose (),...).④SEP Specifies the delimiter, the default is a space, if you read the CSV file, you must set a comma, in order to split the comma into a data frame! Quote is a quotation mark, and the default is double quotation marks. Dec is the representation of a decimal point, which is the default. Skip is to determine whether certain rows are skipped. Strip.white determines whether white space characters are eliminated. Blank.lines.skip determines whether blank lines are skipped. COMMENT.CHAR Specifies the guide symbol used to represent the comment. ⑤header to determine if the first row in the data file is a caption. The default F, that is, that the data file does not have a title, that is, the first line is the beginning of data!
2. Read external file read.csv ()---CSV
Unlike read.table, the default parameters for Read.csv are different. Note The default values for header and Sep. read.csv (file, Header = true, Sep = ",", quote= "\" ", dec=". ", fill = True, comment.char=" ")because CSV is the meaning of comma segmentation, of course, Sep must be a comma. The header is also titled by default. Fill is populated by default, that is, when rows are not equal, the blank field automatically adds the established value. If you use the default settings, you can write: Mydata2<-read.csv (File.choose ()), very simple. It is not recommended for the way the Clipboard is read. The reason we use the read file is to increase
the reusability of the program, and reading the Clipboard obviously destroys that intention. Therefore, use the file path or file selection form as much as you should.
R Language Learning notes Excel file read