0

I've written a function that simulates gene expressions (i.e. a matrix with random values). First row and column stay for gene and experiments names.

The data generated by the function looks OK in Excel and in R, when i read it in with read.table("file.csv", row.names=1, header = T). But in a web-tool col and row names are quoted.

Q: How can i get rid of those quotes?

 # save sample data as csv file
  if (write2csv) {
     write.table(sample.data, file = file.path, sep = "\t", col.names = NA)
   } else {
     return(sample.data)
   }
}
SpikeBZ
  • 17
  • 7
  • clearly better (You can judge by yourself). I remove my downvote. and FYI information you can read [this on how to make a great question](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – agstudy Jul 14 '13 at 13:24
  • Once I get "write more", then I get "write less" :) I need some time to figure it out how it works here, there's no need to downvote everytime one makes "mistake". Thank for your hints. – SpikeBZ Jul 14 '13 at 13:51

2 Answers2

1

the read/write functions in R have the arguments col/row.names. When you write a table you can use quote=FALSE, so you data will stay without quotes. Also when you read.csv, you can use for example use row.names=1 to set the first column of the table as row names.

agstudy
  • 119,832
  • 17
  • 199
  • 261
user1265067
  • 867
  • 1
  • 10
  • 26
0

Use quote=FALSE in write.table (the default is TRUE). From the man page:

quote: a logical value (TRUE or FALSE) or a numeric vector. If TRUE, any character or factor columns will be surrounded by double quotes. If a numeric vector, its elements are taken as the indices of columns to quote. In both cases, row and column names are quoted if they are written. If FALSE, nothing is quoted.

Itamar
  • 2,111
  • 13
  • 16