首页 > 代码库 > R in action -- 2.3 数据输入

R in action -- 2.3 数据输入

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 数据输入