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;
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
add a comment |
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
1
If you are passing the column names, maybe wrap inget
, likeget(loop1.1) / get(loop1.2)
stackoverflow.com/q/12391950
– Frank
Mar 25 at 20:58
add a comment |
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
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
r data.table
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 inget
, likeget(loop1.1) / get(loop1.2)
stackoverflow.com/q/12391950
– Frank
Mar 25 at 20:58
add a comment |
1
If you are passing the column names, maybe wrap inget
, likeget(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
add a comment |
1 Answer
1
active
oldest
votes
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)
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)
add a comment |
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)
add a comment |
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)
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)
answered Mar 25 at 20:49
Corey LevinsonCorey Levinson
3253 silver badges12 bronze badges
3253 silver badges12 bronze badges
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
If you are passing the column names, maybe wrap in
get
, likeget(loop1.1) / get(loop1.2)
stackoverflow.com/q/12391950– Frank
Mar 25 at 20:58