- Hands-On Data Science with Anaconda
- Dr. Yuxing Yan James Yan
- 180字
- 2021-06-25 21:08:49
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:

推薦閱讀
- 大數(shù)據(jù)導(dǎo)論:思維、技術(shù)與應(yīng)用
- 反饋系統(tǒng):多學(xué)科視角(原書(shū)第2版)
- Visual C# 2008開(kāi)發(fā)技術(shù)詳解
- 精通Excel VBA
- 工業(yè)機(jī)器人入門實(shí)用教程(KUKA機(jī)器人)
- 水晶石精粹:3ds max & ZBrush三維數(shù)字靜幀藝術(shù)
- 四向穿梭式自動(dòng)化密集倉(cāng)儲(chǔ)系統(tǒng)的設(shè)計(jì)與控制
- 數(shù)據(jù)通信與計(jì)算機(jī)網(wǎng)絡(luò)
- 基于32位ColdFire構(gòu)建嵌入式系統(tǒng)
- Linux嵌入式系統(tǒng)開(kāi)發(fā)
- AI的25種可能
- 網(wǎng)絡(luò)服務(wù)器搭建與管理
- Web編程基礎(chǔ)
- 數(shù)據(jù)清洗
- 分布式Java應(yīng)用