You didn't describe the exact format of the .gpr files.
There are 32 heading lines in each file, which are now hidden from R
community.
You 'skip' 31 of them in read.table, and one more plays header
('header=T').
Since you are using read.table, your files are usual ascii files.
You shoud use 'cat' and/or 'write.table' R functions to
accomplish your
task. There are some more functions exist.
Using them, you should explicitly write those 32 lines, and then write the
rest contents of the resulting data frame.
Jenny persson wrote:>
> Dear R-users,
>
> I have 10 data files in gpr format (dat1.gpr,...,dat10.gpr). I want to
> read in these files one by one in R and then add one extra column (called
> log) to each data file as below
>
> data.file=sort(dir(path ='C:/Documents and Settings/ Mina
> dokument/data1, pattern = ".gpr$",full.names = TRUE))
> num.data.files<- length(data.file)
> num.data.files
>
> i=1
> ### read one data file
> data<-read.table(file >
data.file[i],skip=31,header=T,sep='\t',na.strings="NA")
>
> ### Define the log ratio using values in column 2 resp 8
> log=as.matrix(log((data[,2])/(data[,8])))
>
> ### append column called log to data frame data, for the reading data
> file
> data=cbind(data,log)
>
> ### Read remaining data files
> for (i in 2:num.data.files) {
>
>
>
data<-read.table(file=data.file[i],header=T,skip=31,sep='\t',na.strings="NA")
>
> log=as.matrix(log((data[,2])/(data[,8])))
> data=cbind(data,log)
> }
>
> Now I want to export these files (with an extra column in each) as
> gpr-files in a folder called data2 but don't know exactly how to do it,
> can you help me out ?
>
> Thanks for your help,
>
> Jenny
>
--
View this message in context:
http://www.nabble.com/Export-multiple-data-files-from-R-tf3587093.html#a10036489
Sent from the R help mailing list archive at Nabble.com.