[R] A problem on sink() and format,suggestions appreciated

Douglas Bates bates at stat.wisc.edu
Wed Jun 1 16:33:23 CEST 2005


luan_sheng wrote:
> Yong Wang å†™é“:
> 
>> Dear R users
>> I get a weired problem when use sink:
>> since the data set pretty big, I sink intermediate result for further
>> use,following
>> lines are consistently used when write data
>>
>> ###########################
>> sink("dataname.txt")
>> data
>> sink()
>> ##########################
>>
>> at first couples of run, all 10 variables are wrote to a file in
>> following format:
>>
>>
>> V1 V2 ....... V10
>> 1 10457 132356.7 ....... 4356.8
>> 2 75690.2 66697 ....... 98777
>> . ..................................
>> 10000 654786 3412.54 ...... 98712.567
>>
>>
>>
>> then I did modifcations somewhere else, the format change to:
>>
>> V1 V2 ....... V9
>> 1 10457 132356.7 ....... 7823.569
>> 2 75690.2 66697 ....... 77024
>> . ..................................
>> 10000 654786 3412.54 ...... 336721
>>
>> V10
>> 1 4356.8
>> 2 98777
>> . .......
>> 10000 98712.567
>>
>> this format is not convenient to read.
>> can you hint me where the problem is and how can I make it back to the
>> first format?
>> I worked on this hours but still can not figure out.
>>
>> any suggestions highly appreciated!
>>
>> thank you
>>
>> yong
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide!
>> http://www.R-project.org/posting-guide.html
>>
> I dont' know the method you write data into your file.But if you use
> "write" function ,then you can specify the colums by the
> "ncolumns". The following is the usage "write"
> 
> write(x, file = "data", ncolumns = if(is.character(x)) 1 else 5, append
> = FALSE)

Alternatively you could save the original R object to a file, remove it
from your worksheet, and load it later when you need it.  See

?save




More information about the R-help mailing list