3
我有一個名爲「data.txt中」文件中的以下數據:如何擺脫R語言中列和行標籤中的引號?
pid 1 2 4 15 18 20
1_at 100 200 89 189 299 788
2_at 8 78 33 89 90 99
3_xt 300 45 53 234 89 34
4_dx 49 34 88 8 9 15
的數據由製表符分隔。
現在我想提取表上的一些列的基礎上,csv文件名爲「vector.csv」的信息,這個載體得到了以下數據:
18,1,4,20
,所以我想用結束脩改後的文件 「datamod.txt」 與製表符分隔的,這將是:
pid 18 1 4 20
1_at 299 100 89 788
2_at 90 8 33 99
3_xt 89 300 53 34
4_dx 9 49 88 15
我做了,有一定的幫助,下面的代碼:
fileName="vector.csv"
con=file(fileName,open="r")
controlfile<-readLines(con)
controls<-controlfile[1]
controlins<-controlfile[2]
test<-paste("pid",controlins,sep=",")
test2<-c(strsplit(test,","))
test3<-c(do.call("rbind",test2))
df<-read.table("data.txt",header=T,check.names=F)
CC <- sapply(df, class)
CC[!names(CC) %in% test3] <- "NULL"
df <- read.table("data.txt", header=T, colClasses=CC,check.names=F)
df<-df[,test3]
write.table(df,"datamod.txt",row.names=FALSE,sep="\t")
,我得到的問題是,我得到的文件格式如下:
"pid" "18" "1" "4" "20"
"1_at" 299 100 89 788
"2_at" 90 8 33 99
"3_xt" 89 300 53 34
"4_dx" 9 49 88 15
我的問題是如何避免這些引號「」出現在我保存的文件標記,以便看起來像數據我想要。
任何幫助?
由於
查看'write.table'的'quote'參數是否設置爲'FALSE' – mnel 2013-02-13 04:39:32