I want to write the results of a table into a file and names of my columns contain the '-' character, but when I write it to a file it replaces all the '-' by a '.'.
function(Result,Path)
{
Num<-0
for(i in 1:length(Result[,1]))
{
if(length(which([Result[i,]>0))>0)
{
temp<-which(Result[i,]>0)]
val<-paste(names(temp),sep="\n")开发者_开发百科
write(val,file=paste(Path,"/Result",Num,".txt",sep=""))
Num<-Num+1
}
}
}
do any one know how to disable this option?
My column names are names of proteins some of them are written in this way YER060W-A
Thank you in advance.
It takes special care to make such an entity. But then you can use the col.names argument and assign colnames(dfrm) to it.
> tst <- data.frame(`a-b`= letters[1:10], `1-2`=1:10, check.names=FALSE)
> colnames(tst)
[1] "a-b" "1-2"
> write.table(tst, file="tst.txt", col.names=colnames(tst) )
Pasted from my editor:
"a-b" "1-2"
"1" "a" 1
"2" "b" 2 snipped the rest...
No success with write.table? I see that write() doesn't have the same repertoire of options as write.table. Let's make an array (rather than a dataframe) with dim names having "-"'s:
DCtest <- array(1:27, c(3,3,3))
dimnames(DCtest) <- list(dim1 =c(a="a-b",b="b-c",c="c%d"),
dim2=letters[4:6],
dim3= letters[7:9])
One quick way to get output is just capture.output():
capture.output(DCtest, file="testm.txt")
testm.txt now looks like this in an editor:
, , dim3 = g
dim2
dim1 d e f
a-b 1 4 7
b-c 2 5 8
c%d 3 6 9
, , dim3 = h
dim2
dim1 d e f
a-b 10 13 16
b-c 11 14 17
c%d 12 15 18
, , dim3 = i
dim2
dim1 d e f
a-b 19 22 25
b-c 20 23 26
c%d 21 24 27
You also should not forget that capture output has an append= parameter if you wanted to append successive slices through an array.
精彩评论