官术网_书友最值得收藏!

Inputting data using R

The R code is shown here:

> path<-"http://archive.ics.uci.edu/ml/machine-learning-databases/" 
> dataSet<-"iris/bezdekIris.data" 
> a<-paste(path,dataSet,sep='') 
> x<-read.csv(a,header=F) 
> colnames(x)<-c("sepalLength","sepalWidth","petalLength","petalWidth","Class") 

The dim(), head(), and tail() functions can be used to look at the size and the first and last several observations of the dataset, shown here:

> dim(x) 
   [1] 150   5 
> head(x,2) 
  sepalLength sepalWidth petalLength petalWidth       Class 
1         5.1        3.5         1.4        0.2 Iris-setosa 
2         4.9        3.0         1.4        0.2 Iris-setosa 
> tail(x,2) 
    sepalLength sepalWidth petalLength petalWidth          Class 
149         6.2        3.4         5.4        2.3 Iris-virginica 
150         5.9        3.0         5.1        1.8 Iris-virginica 

Alternatively, we can use other R functions to input data from an external data file. Those functions include the read.table(), read.delim(), and read.fwf() functions. To find out all functions starting with read., we could apply the apropos() function, shown here:

> apropos("read.") 
 [1] ".read.xls"        ".readRDS"         "read.csv"         
 [4] "read.csv2"        "read.dcf"         "read.delim"       
 [7] "read.delim2"      "read.DIF"         "read.fortran"     
[10] "read.ftable"      "read.fwf"         "read.lines"       
[13] "read.links"       "read.lynx"        "read.socket"      
[16] "read.table"       "read.w3m"         "read.xls"         
[19] "readBin"          "readChar"         "readCitationFile" 
[22] "readClipboard"    "readline"         "readLines"        
[25] "readRDS"          "readRegistry"     "readRenviron"     
[28] "readSeries"       "spreads"          "spreadSeries"     
[31] "Sys.readlink"     

To find out the exact usage of inpidual functions, we use the help() function. For example, after issuing help (read.fwf), we can find information about this specific function, shown in the screenshot in the first several lines:

主站蜘蛛池模板: 沧州市| 平湖市| 柳林县| 河池市| 文昌市| 桓台县| 中阳县| 凭祥市| 武义县| 佛学| 海南省| 高阳县| 开平市| 山东| 波密县| 卓资县| 琼海市| 应用必备| 和林格尔县| 慈利县| 综艺| 乐平市| 银川市| 呼玛县| 固镇县| 嘉荫县| 瓦房店市| 达日县| 三原县| 游戏| 南宫市| 鄂尔多斯市| 武清区| 霍山县| 临猗县| 星座| 库尔勒市| 湖口县| 洛隆县| 汤阴县| 阜宁县|