1. 程式人生 > >R in action -- 2.3 數據輸入

R in action -- 2.3 數據輸入

ref cpp people 2.3 excel com 導入 data 輸入

R in action -- 2.3 數據輸入

1、從CSV文件導入數據

> gtades <- read.table("1.csv",header=TRUE,sep=",")
> gtades
  ID name age
1  1  qqw  15
2  2  eew  56
3  3  rrw  43
4  4  ttw  58

2、從Excel導入數據

安裝openxlsx包

> install.packages("openxlsx")
Installing package into ‘C:/Users/iamfe/Documents/R/win-library/3.4’
(as ‘lib’ is unspecified)
also installing the dependency ‘Rcpp’

trying URL ‘https://cran.rstudio.com/bin/windows/contrib/3.4/Rcpp_0.12.11.zip‘
Content type ‘application/zip‘ length 3380346 bytes (3.2 MB)
downloaded 3.2 MB

trying URL ‘https://cran.rstudio.com/bin/windows/contrib/3.4/openxlsx_4.0.17.zip‘
Content type ‘application/zip‘ length 2430742 bytes (2.3 MB)
downloaded 2.3 MB

package ‘Rcpp’ successfully unpacked and MD5 sums checked
package ‘openxlsx’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
	C:\Users\iamfe\AppData\Local\Temp\Rtmp6h0MaS\downloaded_packages
> library(openxlsx)
> read.xlsx("1.xlsx")
  ID name age
1  1  qqw  15
2  2  eew  56
3  3  rrw  43
4  4  ttw  58
> 

R in action -- 2.3 數據輸入