读取数据(txt文件,制表符分隔)
E盘的Rdata是存放数据的目录
> mydf <- read.table("E:/Rdata/myfile.txt", header=TRUE, sep="\t")
> mydf
显示如下:
X
1 AA 8 5 4
2 AB 3 7 9
3 AC 2 6 1
4 AD 3 4 7 8
...
> mydf <- subset(mydf, select = -X )
这样就删除了 X 这一列
> mydf
显示如下:
1 8 5 4
2 3 7 9
3 2 6 1
4 3 4 7 8
...
其它命令:
> mydataframe <- data.frame(a=1:3, d=2:4, c=3:5, b=4:6)
> mydataframe
a d c b
1 1 2 3 4
2 2 3 4 5
3 3 4 5 6 如果用以下命令读取myfile.txt (结果是没有了X,T1,T2,T3,T4,而且作为矩阵读入)
> df1 <- unname(as.matrix(read.table("E:/Rdata/myfile.txt", row.names=NULL,header=T, sep="\t")))
> df1
[,1] [,2] [,3] [,4] [,5]
[1,] "AA" "8" "5" "4" "6"
[2,] "AB" "3" "7" "9" "2"
[3,] "AC" "2" "6" "1" "0"
[4,] "AD" "3" "4" "7"