R how to print different types of variables into one txt file Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!How to flush output of print function?How do I hide an element when printing a web page?Print a file skipping first X lines in BashHow to use HTML to print header and footer on every printed page of a document?How to print objects of class using print()?The difference between sys.stdout.write and print?How to print to stderr in Python?Print string and variable contents on the same line in RPass R object name as argument in shellSelectively Import only Json data in txt file into R.

AppleTVs create a chatty alternate WiFi network

Flash light on something

Central Vacuuming: Is it worth it, and how does it compare to normal vacuuming?

How to compare two different files line by line in unix?

Would it be easier to apply for a UK visa if there is a host family to sponsor for you in going there?

Why are my pictures showing a dark band on one edge?

Girl Hackers - Logic Puzzle

Did Mueller's report provide an evidentiary basis for the claim of Russian govt election interference via social media?

Can a sorcerer use careful spell on himself?

What does 丫 mean? 丫是什么意思?

Is CEO the "profession" with the most psychopaths?

Karn the great creator - 'card from outside the game' in sealed

Deconstruction is ambiguous

Putting class ranking in CV, but against dept guidelines

How were pictures turned from film to a big picture in a picture frame before digital scanning?

Crossing US/Canada Border for less than 24 hours

The test team as an enemy of development? And how can this be avoided?

How many time has Arya actually used Needle?

Significance of Cersei's obsession with elephants?

Why weren't discrete x86 CPUs ever used in game hardware?

In musical terms, what properties are varied by the human voice to produce different words / syllables?

What would you call this weird metallic apparatus that allows you to lift people?

What is the meaning of 'breadth' in breadth first search?

Is multiple magic items in one inherently imbalanced?



R how to print different types of variables into one txt file



Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!How to flush output of print function?How do I hide an element when printing a web page?Print a file skipping first X lines in BashHow to use HTML to print header and footer on every printed page of a document?How to print objects of class using print()?The difference between sys.stdout.write and print?How to print to stderr in Python?Print string and variable contents on the same line in RPass R object name as argument in shellSelectively Import only Json data in txt file into R.



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








0















I have a lm model, a numeric vector from vif function, and some character variables.



gvmodel<-gvlma(lmFit)
VIF<-sqrt(vif(lmFit))
Str1<-"Original R-square=".567"
Str2<-"Cross-validated R-Square=.123"


I would like to print content of all into one single txt file. I tried cat and capture.output.



cat(gvmodel,VIF,Str1, file="E:/.../text.txt")
capture.output(paste(gvmodel,VIF,...,sep=""),file="E:/.../text.txt")


Obviously this did not work. Anyone how to print them into a single txt file? Thanks










share|improve this question
























  • Str1<-""Original R-square=".567" should be Str1 <- "Original R-square=.567" What error message is R throwing?

    – brettljausn
    Mar 22 at 11:11











  • Sorry that was just a typo here

    – davidzxc574
    Mar 23 at 14:05

















0















I have a lm model, a numeric vector from vif function, and some character variables.



gvmodel<-gvlma(lmFit)
VIF<-sqrt(vif(lmFit))
Str1<-"Original R-square=".567"
Str2<-"Cross-validated R-Square=.123"


I would like to print content of all into one single txt file. I tried cat and capture.output.



cat(gvmodel,VIF,Str1, file="E:/.../text.txt")
capture.output(paste(gvmodel,VIF,...,sep=""),file="E:/.../text.txt")


Obviously this did not work. Anyone how to print them into a single txt file? Thanks










share|improve this question
























  • Str1<-""Original R-square=".567" should be Str1 <- "Original R-square=.567" What error message is R throwing?

    – brettljausn
    Mar 22 at 11:11











  • Sorry that was just a typo here

    – davidzxc574
    Mar 23 at 14:05













0












0








0








I have a lm model, a numeric vector from vif function, and some character variables.



gvmodel<-gvlma(lmFit)
VIF<-sqrt(vif(lmFit))
Str1<-"Original R-square=".567"
Str2<-"Cross-validated R-Square=.123"


I would like to print content of all into one single txt file. I tried cat and capture.output.



cat(gvmodel,VIF,Str1, file="E:/.../text.txt")
capture.output(paste(gvmodel,VIF,...,sep=""),file="E:/.../text.txt")


Obviously this did not work. Anyone how to print them into a single txt file? Thanks










share|improve this question
















I have a lm model, a numeric vector from vif function, and some character variables.



gvmodel<-gvlma(lmFit)
VIF<-sqrt(vif(lmFit))
Str1<-"Original R-square=".567"
Str2<-"Cross-validated R-Square=.123"


I would like to print content of all into one single txt file. I tried cat and capture.output.



cat(gvmodel,VIF,Str1, file="E:/.../text.txt")
capture.output(paste(gvmodel,VIF,...,sep=""),file="E:/.../text.txt")


Obviously this did not work. Anyone how to print them into a single txt file? Thanks







r printing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 23 at 14:06







davidzxc574

















asked Mar 22 at 11:02









davidzxc574davidzxc574

9110




9110












  • Str1<-""Original R-square=".567" should be Str1 <- "Original R-square=.567" What error message is R throwing?

    – brettljausn
    Mar 22 at 11:11











  • Sorry that was just a typo here

    – davidzxc574
    Mar 23 at 14:05

















  • Str1<-""Original R-square=".567" should be Str1 <- "Original R-square=.567" What error message is R throwing?

    – brettljausn
    Mar 22 at 11:11











  • Sorry that was just a typo here

    – davidzxc574
    Mar 23 at 14:05
















Str1<-""Original R-square=".567" should be Str1 <- "Original R-square=.567" What error message is R throwing?

– brettljausn
Mar 22 at 11:11





Str1<-""Original R-square=".567" should be Str1 <- "Original R-square=.567" What error message is R throwing?

– brettljausn
Mar 22 at 11:11













Sorry that was just a typo here

– davidzxc574
Mar 23 at 14:05





Sorry that was just a typo here

– davidzxc574
Mar 23 at 14:05












2 Answers
2






active

oldest

votes


















1














Sink() works. Sink a txt file path and name, run any command that produces text outputs and they will be captured in the txt file. And finally sink() to close.



 sink("E:/.../Sink.txt")
gvmodel
sqrt(vif(ModeName))
sink()





share|improve this answer






























    0














    In your code gvmodel<-gvlma(lmFit) produces gvlma object. It cannot be directly printed to .txt file as such. You can transform it first to characters using as.character() option:



    gvmodel<-gvlma(lmFit)
    gvmodel <- as.character(gvmodel)


    The result is printable for example with cat. So if you put all this together:



    gvmodel<-gvlma(lmFit)
    gvmodel <- as.character(gvmodel)
    VIF<-sqrt(vif(lmFit))
    Str1<-"Original R-square=.567"
    Str2<-"Cross-validated R-Square=.123" # NB the corrected quotation marks

    cat(gvmodel,VIF,Str1, file="yourfile.txt",sep="t")





    share|improve this answer

























    • Thanks for the advice. I transformed gvmodel into character and it was printed out like this: lm(formula = Murder ~ ., data = DataTraining) Murder ~ Population + Illiteracy + Income + Frost c(Alabama = 4.04095098567961, Arizona = -1.50265504165748, California = -0.0650525845054262, Colorado = 1.54774873568549, Connecticut = -3.61072262553982... Residuals and effects of every observation was printed without changing line.

      – davidzxc574
      Mar 25 at 2:18











    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55298221%2fr-how-to-print-different-types-of-variables-into-one-txt-file%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Sink() works. Sink a txt file path and name, run any command that produces text outputs and they will be captured in the txt file. And finally sink() to close.



     sink("E:/.../Sink.txt")
    gvmodel
    sqrt(vif(ModeName))
    sink()





    share|improve this answer



























      1














      Sink() works. Sink a txt file path and name, run any command that produces text outputs and they will be captured in the txt file. And finally sink() to close.



       sink("E:/.../Sink.txt")
      gvmodel
      sqrt(vif(ModeName))
      sink()





      share|improve this answer

























        1












        1








        1







        Sink() works. Sink a txt file path and name, run any command that produces text outputs and they will be captured in the txt file. And finally sink() to close.



         sink("E:/.../Sink.txt")
        gvmodel
        sqrt(vif(ModeName))
        sink()





        share|improve this answer













        Sink() works. Sink a txt file path and name, run any command that produces text outputs and they will be captured in the txt file. And finally sink() to close.



         sink("E:/.../Sink.txt")
        gvmodel
        sqrt(vif(ModeName))
        sink()






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 25 at 10:25









        davidzxc574davidzxc574

        9110




        9110























            0














            In your code gvmodel<-gvlma(lmFit) produces gvlma object. It cannot be directly printed to .txt file as such. You can transform it first to characters using as.character() option:



            gvmodel<-gvlma(lmFit)
            gvmodel <- as.character(gvmodel)


            The result is printable for example with cat. So if you put all this together:



            gvmodel<-gvlma(lmFit)
            gvmodel <- as.character(gvmodel)
            VIF<-sqrt(vif(lmFit))
            Str1<-"Original R-square=.567"
            Str2<-"Cross-validated R-Square=.123" # NB the corrected quotation marks

            cat(gvmodel,VIF,Str1, file="yourfile.txt",sep="t")





            share|improve this answer

























            • Thanks for the advice. I transformed gvmodel into character and it was printed out like this: lm(formula = Murder ~ ., data = DataTraining) Murder ~ Population + Illiteracy + Income + Frost c(Alabama = 4.04095098567961, Arizona = -1.50265504165748, California = -0.0650525845054262, Colorado = 1.54774873568549, Connecticut = -3.61072262553982... Residuals and effects of every observation was printed without changing line.

              – davidzxc574
              Mar 25 at 2:18















            0














            In your code gvmodel<-gvlma(lmFit) produces gvlma object. It cannot be directly printed to .txt file as such. You can transform it first to characters using as.character() option:



            gvmodel<-gvlma(lmFit)
            gvmodel <- as.character(gvmodel)


            The result is printable for example with cat. So if you put all this together:



            gvmodel<-gvlma(lmFit)
            gvmodel <- as.character(gvmodel)
            VIF<-sqrt(vif(lmFit))
            Str1<-"Original R-square=.567"
            Str2<-"Cross-validated R-Square=.123" # NB the corrected quotation marks

            cat(gvmodel,VIF,Str1, file="yourfile.txt",sep="t")





            share|improve this answer

























            • Thanks for the advice. I transformed gvmodel into character and it was printed out like this: lm(formula = Murder ~ ., data = DataTraining) Murder ~ Population + Illiteracy + Income + Frost c(Alabama = 4.04095098567961, Arizona = -1.50265504165748, California = -0.0650525845054262, Colorado = 1.54774873568549, Connecticut = -3.61072262553982... Residuals and effects of every observation was printed without changing line.

              – davidzxc574
              Mar 25 at 2:18













            0












            0








            0







            In your code gvmodel<-gvlma(lmFit) produces gvlma object. It cannot be directly printed to .txt file as such. You can transform it first to characters using as.character() option:



            gvmodel<-gvlma(lmFit)
            gvmodel <- as.character(gvmodel)


            The result is printable for example with cat. So if you put all this together:



            gvmodel<-gvlma(lmFit)
            gvmodel <- as.character(gvmodel)
            VIF<-sqrt(vif(lmFit))
            Str1<-"Original R-square=.567"
            Str2<-"Cross-validated R-Square=.123" # NB the corrected quotation marks

            cat(gvmodel,VIF,Str1, file="yourfile.txt",sep="t")





            share|improve this answer















            In your code gvmodel<-gvlma(lmFit) produces gvlma object. It cannot be directly printed to .txt file as such. You can transform it first to characters using as.character() option:



            gvmodel<-gvlma(lmFit)
            gvmodel <- as.character(gvmodel)


            The result is printable for example with cat. So if you put all this together:



            gvmodel<-gvlma(lmFit)
            gvmodel <- as.character(gvmodel)
            VIF<-sqrt(vif(lmFit))
            Str1<-"Original R-square=.567"
            Str2<-"Cross-validated R-Square=.123" # NB the corrected quotation marks

            cat(gvmodel,VIF,Str1, file="yourfile.txt",sep="t")






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Mar 22 at 12:33

























            answered Mar 22 at 12:22









            OkaOka

            73729




            73729












            • Thanks for the advice. I transformed gvmodel into character and it was printed out like this: lm(formula = Murder ~ ., data = DataTraining) Murder ~ Population + Illiteracy + Income + Frost c(Alabama = 4.04095098567961, Arizona = -1.50265504165748, California = -0.0650525845054262, Colorado = 1.54774873568549, Connecticut = -3.61072262553982... Residuals and effects of every observation was printed without changing line.

              – davidzxc574
              Mar 25 at 2:18

















            • Thanks for the advice. I transformed gvmodel into character and it was printed out like this: lm(formula = Murder ~ ., data = DataTraining) Murder ~ Population + Illiteracy + Income + Frost c(Alabama = 4.04095098567961, Arizona = -1.50265504165748, California = -0.0650525845054262, Colorado = 1.54774873568549, Connecticut = -3.61072262553982... Residuals and effects of every observation was printed without changing line.

              – davidzxc574
              Mar 25 at 2:18
















            Thanks for the advice. I transformed gvmodel into character and it was printed out like this: lm(formula = Murder ~ ., data = DataTraining) Murder ~ Population + Illiteracy + Income + Frost c(Alabama = 4.04095098567961, Arizona = -1.50265504165748, California = -0.0650525845054262, Colorado = 1.54774873568549, Connecticut = -3.61072262553982... Residuals and effects of every observation was printed without changing line.

            – davidzxc574
            Mar 25 at 2:18





            Thanks for the advice. I transformed gvmodel into character and it was printed out like this: lm(formula = Murder ~ ., data = DataTraining) Murder ~ Population + Illiteracy + Income + Frost c(Alabama = 4.04095098567961, Arizona = -1.50265504165748, California = -0.0650525845054262, Colorado = 1.54774873568549, Connecticut = -3.61072262553982... Residuals and effects of every observation was printed without changing line.

            – davidzxc574
            Mar 25 at 2:18

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55298221%2fr-how-to-print-different-types-of-variables-into-one-txt-file%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript