解压下载的数据到:E:\R\R-beginer-guide\data\RBook
在R控制台执行:
Squid <- read.table(file = "E:/R/R-beginer-guide/data/RBook/squid.txt",header=TRUE)
Squid
Sample Year Month Location Sex GSI
1 1 1 1 1 2 10.4432
2 2 1 1 3 2 9.8331
3 3 1 1 1 2 9.7356
4 4 1 1 1 2 9.3107
5 5 1 1 1 2 8.9926
6 6 1 1 1 2 8.7707
7 7 1 1 1 2 8.2576
8 8 1 1 3 2 7.4045
9 9 1 1 3 2 7.2156
10 10 1 2 1 2 6.8372
11 11 1 1 1 2 6.3882
12 12 1 6 1 2 6.3672
13 13 1 2 1 2 6.2998
14 14 1 1 1 2 6.0726
..................
..................
..................
省略其余数据
这个命令实现了把数据从squid.txt文件中读取出来以数据框的形式存储到Squid中
Squid <- read.table(file = "E:/R/R-beginer-guide/data/RBook/squid.txt",header=TRUE) #命令真正内容: Squid <- read.table(file = "E:/R/R-beginer-guide/data/RBook/squid.txt",header=TRUE,dec=".")
dec指定小数点是什么。
技巧:
通过setwd设置工作目录执行read.table函数事就不需要指定目录了。
scan也可以导入数据不过read.table是将数据导入到数据框中,而scan是将数据导入到矩阵中。
从其他统计软件中导入和从数据库导入数据省略。没条件实验。
原文:http://www.cnblogs.com/Martin-9/p/5379132.html