How does R decide on the mode of a vector?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'd started learning R recently and in one of the practice questions, this was asked
What will be the output of
mode(c(12, 45, "30", 34*56))
Now, since the numeric
data was in majority, I thought the answer would be numeric
. But the given answer (which I'd later verified in R console) was character
.
What is the reason behind this?
r
|
show 1 more comment
I'd started learning R recently and in one of the practice questions, this was asked
What will be the output of
mode(c(12, 45, "30", 34*56))
Now, since the numeric
data was in majority, I thought the answer would be numeric
. But the given answer (which I'd later verified in R console) was character
.
What is the reason behind this?
r
1
numeric can always coerced to character.
– jogo
Nov 16 '18 at 14:13
3
rundebugonce(mode)
andmode(c(12, 45, "30", 34*56))
again for playing with the internals, hence the why.
– Nutle
Nov 16 '18 at 14:14
adv-r.had.co.nz/Data-structures.html
– hrbrmstr
Nov 16 '18 at 14:14
@Nutle I'm new to R, basically coding and I really didn't understand what was happening there
– John Cleaver
Nov 16 '18 at 14:17
1
@JohnCleaver so it's a useful tool to learn then! You basically enter a debug mode, where you can see the internal code of the function, can run and evaluate the code line by line and see how does the result change. Here, for example, you can tryis.expression(x)
,is.call(x)
, etc, and understand which part will be executed by themode
function in the end. Finally, just typex
and see how does your input look like, when passed to mode.
– Nutle
Nov 16 '18 at 14:22
|
show 1 more comment
I'd started learning R recently and in one of the practice questions, this was asked
What will be the output of
mode(c(12, 45, "30", 34*56))
Now, since the numeric
data was in majority, I thought the answer would be numeric
. But the given answer (which I'd later verified in R console) was character
.
What is the reason behind this?
r
I'd started learning R recently and in one of the practice questions, this was asked
What will be the output of
mode(c(12, 45, "30", 34*56))
Now, since the numeric
data was in majority, I thought the answer would be numeric
. But the given answer (which I'd later verified in R console) was character
.
What is the reason behind this?
r
r
asked Nov 16 '18 at 14:09
John CleaverJohn Cleaver
285
285
1
numeric can always coerced to character.
– jogo
Nov 16 '18 at 14:13
3
rundebugonce(mode)
andmode(c(12, 45, "30", 34*56))
again for playing with the internals, hence the why.
– Nutle
Nov 16 '18 at 14:14
adv-r.had.co.nz/Data-structures.html
– hrbrmstr
Nov 16 '18 at 14:14
@Nutle I'm new to R, basically coding and I really didn't understand what was happening there
– John Cleaver
Nov 16 '18 at 14:17
1
@JohnCleaver so it's a useful tool to learn then! You basically enter a debug mode, where you can see the internal code of the function, can run and evaluate the code line by line and see how does the result change. Here, for example, you can tryis.expression(x)
,is.call(x)
, etc, and understand which part will be executed by themode
function in the end. Finally, just typex
and see how does your input look like, when passed to mode.
– Nutle
Nov 16 '18 at 14:22
|
show 1 more comment
1
numeric can always coerced to character.
– jogo
Nov 16 '18 at 14:13
3
rundebugonce(mode)
andmode(c(12, 45, "30", 34*56))
again for playing with the internals, hence the why.
– Nutle
Nov 16 '18 at 14:14
adv-r.had.co.nz/Data-structures.html
– hrbrmstr
Nov 16 '18 at 14:14
@Nutle I'm new to R, basically coding and I really didn't understand what was happening there
– John Cleaver
Nov 16 '18 at 14:17
1
@JohnCleaver so it's a useful tool to learn then! You basically enter a debug mode, where you can see the internal code of the function, can run and evaluate the code line by line and see how does the result change. Here, for example, you can tryis.expression(x)
,is.call(x)
, etc, and understand which part will be executed by themode
function in the end. Finally, just typex
and see how does your input look like, when passed to mode.
– Nutle
Nov 16 '18 at 14:22
1
1
numeric can always coerced to character.
– jogo
Nov 16 '18 at 14:13
numeric can always coerced to character.
– jogo
Nov 16 '18 at 14:13
3
3
run
debugonce(mode)
and mode(c(12, 45, "30", 34*56))
again for playing with the internals, hence the why.– Nutle
Nov 16 '18 at 14:14
run
debugonce(mode)
and mode(c(12, 45, "30", 34*56))
again for playing with the internals, hence the why.– Nutle
Nov 16 '18 at 14:14
adv-r.had.co.nz/Data-structures.html
– hrbrmstr
Nov 16 '18 at 14:14
adv-r.had.co.nz/Data-structures.html
– hrbrmstr
Nov 16 '18 at 14:14
@Nutle I'm new to R, basically coding and I really didn't understand what was happening there
– John Cleaver
Nov 16 '18 at 14:17
@Nutle I'm new to R, basically coding and I really didn't understand what was happening there
– John Cleaver
Nov 16 '18 at 14:17
1
1
@JohnCleaver so it's a useful tool to learn then! You basically enter a debug mode, where you can see the internal code of the function, can run and evaluate the code line by line and see how does the result change. Here, for example, you can try
is.expression(x)
, is.call(x)
, etc, and understand which part will be executed by the mode
function in the end. Finally, just type x
and see how does your input look like, when passed to mode.– Nutle
Nov 16 '18 at 14:22
@JohnCleaver so it's a useful tool to learn then! You basically enter a debug mode, where you can see the internal code of the function, can run and evaluate the code line by line and see how does the result change. Here, for example, you can try
is.expression(x)
, is.call(x)
, etc, and understand which part will be executed by the mode
function in the end. Finally, just type x
and see how does your input look like, when passed to mode.– Nutle
Nov 16 '18 at 14:22
|
show 1 more comment
1 Answer
1
active
oldest
votes
R has a hierarchy of returning the mode.
As given in the documentation for mode
, (?mode
to open its documentation)
"logical", "integer", "double", "complex", "raw", "character", "list", "expression", "name", "symbol" and "function"
gives the way how R returns the mode.
Here, if the vector has even one function
, the mode is function
. If there is no function
present, R checks for symbol
and so on.
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%2f53339490%2fhow-does-r-decide-on-the-mode-of-a-vector%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
R has a hierarchy of returning the mode.
As given in the documentation for mode
, (?mode
to open its documentation)
"logical", "integer", "double", "complex", "raw", "character", "list", "expression", "name", "symbol" and "function"
gives the way how R returns the mode.
Here, if the vector has even one function
, the mode is function
. If there is no function
present, R checks for symbol
and so on.
add a comment |
R has a hierarchy of returning the mode.
As given in the documentation for mode
, (?mode
to open its documentation)
"logical", "integer", "double", "complex", "raw", "character", "list", "expression", "name", "symbol" and "function"
gives the way how R returns the mode.
Here, if the vector has even one function
, the mode is function
. If there is no function
present, R checks for symbol
and so on.
add a comment |
R has a hierarchy of returning the mode.
As given in the documentation for mode
, (?mode
to open its documentation)
"logical", "integer", "double", "complex", "raw", "character", "list", "expression", "name", "symbol" and "function"
gives the way how R returns the mode.
Here, if the vector has even one function
, the mode is function
. If there is no function
present, R checks for symbol
and so on.
R has a hierarchy of returning the mode.
As given in the documentation for mode
, (?mode
to open its documentation)
"logical", "integer", "double", "complex", "raw", "character", "list", "expression", "name", "symbol" and "function"
gives the way how R returns the mode.
Here, if the vector has even one function
, the mode is function
. If there is no function
present, R checks for symbol
and so on.
answered Nov 16 '18 at 14:24
MoltresMoltres
390116
390116
add a comment |
add a comment |
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%2f53339490%2fhow-does-r-decide-on-the-mode-of-a-vector%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
numeric can always coerced to character.
– jogo
Nov 16 '18 at 14:13
3
run
debugonce(mode)
andmode(c(12, 45, "30", 34*56))
again for playing with the internals, hence the why.– Nutle
Nov 16 '18 at 14:14
adv-r.had.co.nz/Data-structures.html
– hrbrmstr
Nov 16 '18 at 14:14
@Nutle I'm new to R, basically coding and I really didn't understand what was happening there
– John Cleaver
Nov 16 '18 at 14:17
1
@JohnCleaver so it's a useful tool to learn then! You basically enter a debug mode, where you can see the internal code of the function, can run and evaluate the code line by line and see how does the result change. Here, for example, you can try
is.expression(x)
,is.call(x)
, etc, and understand which part will be executed by themode
function in the end. Finally, just typex
and see how does your input look like, when passed to mode.– Nutle
Nov 16 '18 at 14:22