Referencing column names in data table =:Select / assign to data.table when variable names are stored in a character vectorHow to sort a dataframe by multiple column(s)Referencing a column vector in a data frame within a loopDrop data frame columns by nameChanging column names of a data frameLoop through columns in a data.table and transform those columnsdata.table vs dplyr: can one do something well the other can't or does poorly?dplyr - mutate: use dynamic variable namesget numeric column values in data table in rIn R produce a running count in column based on previous column with numeric valuesSubtract two data.tables

Better random (unique) file name

Did William Shakespeare hide things in his writings?

Bringing coumarin-containing liquor into the USA

Do intermediate subdomains need to exist?

What happens if the limit of 4 billion files was exceeded in an ext4 partition?

Is conquering your neighbors to fight a greater enemy a valid strategy?

Passwordless authentication - how invalidate login code

Chilling juice in copper vessel

Multi-user CRUD: Valid, Problem, or Error?

Wearing special clothes in public while in niddah- isn't this a lack of tznius?

Why do we need a bootloader separate from our application program in microcontrollers?

Who goes first? Person disembarking bus or the bicycle?

In the Seventh Seal why does Death let the chess game happen?

Shipped package arrived - didn't order, possible scam?

Find max number you can create from an array of numbers

Wouldn't putting an electronic key inside a small Faraday cage render it completely useless?

Why did Super-VGA offer the 5:4 1280*1024 resolution?

Is this car delivery via Ebay Motors on Craigslist a scam?

Park the computer

Why no parachutes in the Orion AA2 abort test?

What is the shape of the upper boundary of water hitting a screen?

How to reclaim personal item I've lent to the office without burning bridges?

How many Jimmys can fit?

Why isn't 10.0.0.0/8 used instead of 192.168.0.0/16 for private addresses?



Referencing column names in data table =:


Select / assign to data.table when variable names are stored in a character vectorHow to sort a dataframe by multiple column(s)Referencing a column vector in a data frame within a loopDrop data frame columns by nameChanging column names of a data frameLoop through columns in a data.table and transform those columnsdata.table vs dplyr: can one do something well the other can't or does poorly?dplyr - mutate: use dynamic variable namesget numeric column values in data table in rIn R produce a running count in column based on previous column with numeric valuesSubtract two data.tables






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I'm running a loop in which two numeric columns are created based on some data. These two column names are generated by the part of the loop they are in. So for example, the first two columns are df$loop1.1 and df$loop1.2 and then in the following loop they'd be df$loop2.1 and df$loop2.2



I need to create a third column that is based off of those two columns like so:



df[, divisioncol := loop1.1 / loop1.2]


However, I'm getting the error



 non-numeric argument to binary operator


Any suggestions?



Solved:



 df[, divisioncol := get(loop1.1)/get(loop2.2)]









share|improve this question



















  • 1





    If you are passing the column names, maybe wrap in get, like get(loop1.1) / get(loop1.2) stackoverflow.com/q/12391950

    – Frank
    Mar 25 at 20:58


















1















I'm running a loop in which two numeric columns are created based on some data. These two column names are generated by the part of the loop they are in. So for example, the first two columns are df$loop1.1 and df$loop1.2 and then in the following loop they'd be df$loop2.1 and df$loop2.2



I need to create a third column that is based off of those two columns like so:



df[, divisioncol := loop1.1 / loop1.2]


However, I'm getting the error



 non-numeric argument to binary operator


Any suggestions?



Solved:



 df[, divisioncol := get(loop1.1)/get(loop2.2)]









share|improve this question



















  • 1





    If you are passing the column names, maybe wrap in get, like get(loop1.1) / get(loop1.2) stackoverflow.com/q/12391950

    – Frank
    Mar 25 at 20:58














1












1








1








I'm running a loop in which two numeric columns are created based on some data. These two column names are generated by the part of the loop they are in. So for example, the first two columns are df$loop1.1 and df$loop1.2 and then in the following loop they'd be df$loop2.1 and df$loop2.2



I need to create a third column that is based off of those two columns like so:



df[, divisioncol := loop1.1 / loop1.2]


However, I'm getting the error



 non-numeric argument to binary operator


Any suggestions?



Solved:



 df[, divisioncol := get(loop1.1)/get(loop2.2)]









share|improve this question
















I'm running a loop in which two numeric columns are created based on some data. These two column names are generated by the part of the loop they are in. So for example, the first two columns are df$loop1.1 and df$loop1.2 and then in the following loop they'd be df$loop2.1 and df$loop2.2



I need to create a third column that is based off of those two columns like so:



df[, divisioncol := loop1.1 / loop1.2]


However, I'm getting the error



 non-numeric argument to binary operator


Any suggestions?



Solved:



 df[, divisioncol := get(loop1.1)/get(loop2.2)]






r data.table






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 25 at 21:00







Justin

















asked Mar 25 at 20:46









JustinJustin

223 bronze badges




223 bronze badges







  • 1





    If you are passing the column names, maybe wrap in get, like get(loop1.1) / get(loop1.2) stackoverflow.com/q/12391950

    – Frank
    Mar 25 at 20:58













  • 1





    If you are passing the column names, maybe wrap in get, like get(loop1.1) / get(loop1.2) stackoverflow.com/q/12391950

    – Frank
    Mar 25 at 20:58








1




1





If you are passing the column names, maybe wrap in get, like get(loop1.1) / get(loop1.2) stackoverflow.com/q/12391950

– Frank
Mar 25 at 20:58






If you are passing the column names, maybe wrap in get, like get(loop1.1) / get(loop1.2) stackoverflow.com/q/12391950

– Frank
Mar 25 at 20:58













1 Answer
1






active

oldest

votes


















0














Your error is caused by a non-numeric argument to a binary operator. The binary operator here is the function /, which is division. This means that either loop1.1 or loop1.2 contains a non-numeric value. Verify this by typing typeof(df$loop1.1) and typeof(df$loop1.2)






share|improve this answer






















    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%2f55346163%2freferencing-column-names-in-data-table%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Your error is caused by a non-numeric argument to a binary operator. The binary operator here is the function /, which is division. This means that either loop1.1 or loop1.2 contains a non-numeric value. Verify this by typing typeof(df$loop1.1) and typeof(df$loop1.2)






    share|improve this answer



























      0














      Your error is caused by a non-numeric argument to a binary operator. The binary operator here is the function /, which is division. This means that either loop1.1 or loop1.2 contains a non-numeric value. Verify this by typing typeof(df$loop1.1) and typeof(df$loop1.2)






      share|improve this answer

























        0












        0








        0







        Your error is caused by a non-numeric argument to a binary operator. The binary operator here is the function /, which is division. This means that either loop1.1 or loop1.2 contains a non-numeric value. Verify this by typing typeof(df$loop1.1) and typeof(df$loop1.2)






        share|improve this answer













        Your error is caused by a non-numeric argument to a binary operator. The binary operator here is the function /, which is division. This means that either loop1.1 or loop1.2 contains a non-numeric value. Verify this by typing typeof(df$loop1.1) and typeof(df$loop1.2)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 25 at 20:49









        Corey LevinsonCorey Levinson

        3253 silver badges12 bronze badges




        3253 silver badges12 bronze badges


















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            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%2f55346163%2freferencing-column-names-in-data-table%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