Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6883633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:24:26+00:00 2026-05-27T05:24:26+00:00

I am working with the following data in R: > str(df) ‘data.frame’: 369269 obs.

  • 0

I am working with the following data in R:

> str(df)
'data.frame':   369269 obs. of  12 variables:
 $ bkod : int  110006 110006 110006 110006 110006 110006 110006 110006 110006 110006 ...
 $ bad  : Factor w/ 215 levels "4. Levent","500 Evler",..: 26 26 26 26 26 26 26 26 26 26 ...
 $ mkod : int  359 359 359 359 359 359 359 359 359 359 ...
 $ mad  : Factor w/ 8643 levels "    Hilal Gida           ",..: 4021 4021 4021 4021 4021 4021 4021 4021 4021 4021 ...
 $ yekod: int  12 12 12 12 12 12 12 12 12 12 ...
 $ yad  : Factor w/ 44 levels "BAKUGAN","BARBIE",..: 1 1 1 1 1 2 2 2 2 2 ...
 $ donem: int  201101 201103 201105 201107 201109 201102 201103 201104 201106 201107 ...
 $ sayi : int  201101 201102 201103 201104 201105 201102 201103 201104 201106 201107 ...
 $ plan : num  5 3 2 7 5 0 2 2 0 2 ...
 $ sevk : int  5 6 4 7 6 3 2 5 5 2 ...
 $ iade : int  4 1 3 5 5 2 2 5 0 2 ...
 $ satis: int  1 5 1 2 1 1 0 0 5 0 ...

bkv <- unique(df$bkod)
> bkv
  [1] 110006 110007 110010 110011 110020 110022 110027 110030 110032 110036 110043 110049 110051 110054 110056 110061 110062 110067 110069 110071 110077
 [22] 110084 110092 110093 110094 110100 110101 110104 110109 110111 110113 110116 110117 110120 110133 110138 110143 110158 110160 110162 110186 110187
 [43] 110198 110202 110208 110213 110214 110216 110218 110219 110222 110224 110229 110232 110234 110235 110247 110249 110250 110252 110255 110256 110262
 [64] 110265 110266 110268 110269 110270 110274 110277 110278 110282 110285 110295 110296 110301 110306 110309 110310 110311 110313 110314 110315 110319
 [85] 110329 110346 110351 110354 110357 110359 110377 110379 110380 110386 110392 110394 110396 110397 110400 110406 110412 110413 110419 110421 110422
[106] 110423 110426 110428 110431 110439 110442 110444 110452 110455 110464 110467 110469 110470 110471 110475 110478 110480 110485 110490 110492 110498
[127] 110499 110503 110505 110506 110508 110509 110512 110514 110517 110518 110519 110523 110532 110534 110537 110540 110543 110544 110545 110546 110547
[148] 110549 110550 110551 110553 110554 110555 110556 110557 110559 110560 110562 110565 110566 110569 110570 110571 110572 110573 110575 110576 110577
[169] 110578 110579 110580 110581 110582 110583 110584 110586 110587 110588 110589 110590 110591 110594 110595 110596 110597 110598 110599 110600 110602
[190] 110603 110605 110606 110607 110608 110609 110610 110611 110612 110613 110614 110615 110616 110617 110619 110620 110621 110622 110623 110624 110625
[211] 110626 110627 110628 110629 110630

What I want to achieve is to make some calculations with respect to each element in bkv and append the results to a txt file using sink inside a For-Loop. So I created the following loop;

for (i in bkv) {
  new <- df[df$bkod==i,]
  dp <- new[new$plan!=new$sevk,]
  medy <- 100*(nrow(dp)/nrow(new))
  sink("Report.txt")
  cat(i, "için müdahale oranı: %", medy, "\n")
}

but it gives the following error:

Error in sink(“Report.txt”) : sink stack is full

It creates Report.txt but it’s an empty file. The report should have 215 lines as bkv has 215 elements.

What am I doing wrong? What should I do to make this loop work correctly and append the results to the text file?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:24:27+00:00Added an answer on May 27, 2026 at 5:24 am

    The function sink sets up a diversion of output to a file. You only do this once, before the loop. The output of cat will then get diverted into your sink file, until you cancel the sink with sink().

    So your code should look something like:

    sink("Report.txt")
    for (i in bkv) {
      new <- df[df$bkod==i,]
      dp <- new[new$plan!=new$sevk,]
      medy <- 100*(nrow(dp)/nrow(new))
      cat(i, "için müdahale oranı: %", medy, "\n")
    }
    sink()
    

    It is possible to have a stack of sink files. The maximum size of this stack will depend on how many open file handles your operating system will allow.


    Warning

    I used sink quite a bit as an R newby. But I think it has some dangerous side effects that you should take note of. The most important is that if your script has errors, and you rerun the script, then your sink(filename) will get added to the stack of sinks.

    So unless you are scrupulous about your book-keeping of the sink stack, this can lead to all kinds of errors.

    In my view it is far better to use the ability of cat to append to a file, e.g:

    cat(..., file="Report.txt", append=TRUE)
    

    Or, even better, write a wrapper function. Something along the lines of:

    catf <- function(..., file="report.txt", append=TRUE){
      cat(..., file=file, append=append)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The following is the data I am working on: __DATA__ Node 1: 98 debug
I am working with a set of data that looks something like the following.
I am working on some legacy code. I have the following data types: typedef
I'm working on a ECG data that basically has the following schema Col 1
I have the following working tar -pcvf base.tar input/myPacket/my2 --exclude-vcs input/myPacket/my3/*.bmp When i have
Working with the following code, I need to return only records where the `point'
I'm working on the following LINQ query: public void GetAuditRuleAgencyRecords(IEnumerable<Entities.AuditRule> rules) { using (LinqModelDataContext
I am working on the following code: import java.io.*; import javax.xml.parsers.*; import javax.xml.transform.*; import
I am working with the following piece; def index @user = User.find(params[:id]) rescue flash[:notice]
I'm trying to get the following code working: string url = String.Format(@SOMEURL); string user

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.