Document directory
- Detailed description of read. Table in R
Detailed description of read. Table in R
Source: http://wnfdsfy.diandian.com/post/2011-10-17/5856100
R is a free software environment for Statistical Computing and graphics. It compiles and runs on a wide variety of UNIX platforms, windows and MACOs. -- http://www.r-project.org/
I am engaged in biological information research and learning. R is often used to process and analyze data. In order to make it easier and more skillful to use R in the future, make some records. Please correct and supplement the deficiencies!
Read. Table, as its name implies, reads a table. In many fields (almost all fields), data is stored in tables. Therefore, it is important and necessary to directly read table data.
For example, there is a table named test.xls on the desktop with the following content:
To read its content, you can perform the following operations.
Where # is followed by a comment, R will turn a blind eye. Note that r commands and symbols must be entered in English. For example, "" cannot be entered as "", and ''cannot be output ''. SEP = '\ t' indicates that the table R is separated by the tab key and has other delimiters. Of course, the famous CVS format file is separated!
Of course, you may want to say that I want to use the first column in excle as the name of the variable column. Read. Table can do this!
Header = true indicates that the first line of the file is the header file (attribute name), and the other line is the value. Then read. Table uses the header file as the name of the variable column.
Look at a more interesting table. The table below has the first column more than the table above, but the first row has not changed. Read. Table can still be read !!
The command is as follows:
Why? I was also very depressed at the time, because the data written with write. Table is always the first row with less data. However, it is correct to read the missing data. After carefully studying read. Table, we know that there is a default option in read. Table. That is:
Info <-read.table('test.xls ')
Equivalent:
Info <- read.table('test.xls', header = FALSE, sep = "", quote = "\"'",dec = ".", row.names, col.names, as.is = !stringsAsFactors, na.strings = "NA", colClasses = NA, nrows = -1, skip = 0, check.names = TRUE, fill = !blank.lines.skip, strip.white = FALSE, blank.lines.skip = TRUE, comment.char = "#", allowEscapes = FALSE, flush = FALSE, stringsAsFactors = default.stringsAsFactors(), fileEncoding = "", encoding = "unknown")
All the following are options. If there is "=", there is a default option. For example, SEP = "": it is separated by blank characters by default, which is invisible characters, such as tab and space. Here, check. Names = true is used to check the name. In fact, if the first row has a value less than the other rows, the first row is used as the column name and the first column is used as the row name. A lot of options... Let's see later ~
Learning R: more? Read. Table (), less Google, no Baidu.
In fact, Baidu has not found the authority and system information of r so far. It's strange that Baidu has resolved R to "day"... I guess.