NA values causing problems in summarise() even when using rm.na = TRUE2019 Community Moderator ElectionPerforming dplyr mutate on subset of columnsFind mean from subset of one column based on ranking in the top 50 of another columnAdvice on writing generic function to encode variables in RR: Fast method to conditionally replace column valuesUse grouped summary to operate in another data.frame column by factorrle(): Return average of lengths only if values == TRUEUsing dplyr to summarise values and store as vector in data frame?Passing (function) user-specified column name to dplyr do()dplyr filter variable set to filter nothing [r]Using dplyr summarise with conditions
Why was Goose renamed from Chewie for the Captain Marvel film?
How do I express some one as a black person?
How did Alan Turing break the enigma code using the hint given by the lady in the bar?
Accepted offer letter, position changed
Why would one plane in this picture not have gear down yet?
How to secure an aircraft at a transient parking space?
Is compression "encryption" under FCC regs?
Good for you! in Russian
Why is computing ridge regression with a Cholesky decomposition much quicker than using SVD?
Child Theme Path Being Ignored With wp_enqueue_scripts
Why does liquid water form when we exhale on a mirror?
Why doesn't this Google Translate ad use the word "Translation" instead of "Translate"?
Examples of a statistic that is not independent of sample's distribution?
What Happens when Passenger Refuses to Fly Boeing 737 Max?
Rewrite the power sum in terms of convolution
What wound would be of little consequence to a biped but terrible for a quadruped?
Can one live in the U.S. and not use a credit card?
Shifting between bemols (flats) and diesis (sharps)in the key signature
How can I get players to stop ignoring or overlooking the plot hooks I'm giving them?
How to detect if C code (which needs 'extern C') is compiled in C++
In the late 1940’s to early 1950’s what technology was available that could melt a LOT of ice?
Reversed Sudoku
Plausibility of Mushroom Buildings
Why the color red for the Republican Party
NA values causing problems in summarise() even when using rm.na = TRUE
2019 Community Moderator ElectionPerforming dplyr mutate on subset of columnsFind mean from subset of one column based on ranking in the top 50 of another columnAdvice on writing generic function to encode variables in RR: Fast method to conditionally replace column valuesUse grouped summary to operate in another data.frame column by factorrle(): Return average of lengths only if values == TRUEUsing dplyr to summarise values and store as vector in data frame?Passing (function) user-specified column name to dplyr do()dplyr filter variable set to filter nothing [r]Using dplyr summarise with conditions
I'm trying to take the mean of some data with NA values, and I would like the NA values to be ignored. A reproducible example would be:
country gdp
1 Austria 25.17
2 Azerbaijan NA
3 Bangladesh 27.79
4 Belarus NA
testdf2 <- data.frame(stringsAsFactors=FALSE,
country = c("Austria", "Azerbaijan", "Bangladesh", "Belarus"),
gdp = c(25.17654, NA, 27.7971, NA)
)
I've tried summarise()
using rm.na = TRUE
and without
library(dplyr)
testdf2 %>% summarise(gdp_mean = mean(gdp))
testdf2 %>% summarise(gdp_mean = mean(gdp), rm.na = TRUE)
but I keep getting output that looks like this:
gdp_mean
1 NA
Can anyone tell me what I'm doing wrong, please?
r dplyr
add a comment |
I'm trying to take the mean of some data with NA values, and I would like the NA values to be ignored. A reproducible example would be:
country gdp
1 Austria 25.17
2 Azerbaijan NA
3 Bangladesh 27.79
4 Belarus NA
testdf2 <- data.frame(stringsAsFactors=FALSE,
country = c("Austria", "Azerbaijan", "Bangladesh", "Belarus"),
gdp = c(25.17654, NA, 27.7971, NA)
)
I've tried summarise()
using rm.na = TRUE
and without
library(dplyr)
testdf2 %>% summarise(gdp_mean = mean(gdp))
testdf2 %>% summarise(gdp_mean = mean(gdp), rm.na = TRUE)
but I keep getting output that looks like this:
gdp_mean
1 NA
Can anyone tell me what I'm doing wrong, please?
r dplyr
2
testdf2 %>% summarise(gdp_mean = mean(gdp, na.rm= TRUE))
– Wen-Ben
Mar 6 at 15:30
1
rm.na = TRUE
should bemean
argument and notsummarise
, so:mean(gdp, rm.na = TRUE)
– kwiscion
Mar 6 at 15:30
add a comment |
I'm trying to take the mean of some data with NA values, and I would like the NA values to be ignored. A reproducible example would be:
country gdp
1 Austria 25.17
2 Azerbaijan NA
3 Bangladesh 27.79
4 Belarus NA
testdf2 <- data.frame(stringsAsFactors=FALSE,
country = c("Austria", "Azerbaijan", "Bangladesh", "Belarus"),
gdp = c(25.17654, NA, 27.7971, NA)
)
I've tried summarise()
using rm.na = TRUE
and without
library(dplyr)
testdf2 %>% summarise(gdp_mean = mean(gdp))
testdf2 %>% summarise(gdp_mean = mean(gdp), rm.na = TRUE)
but I keep getting output that looks like this:
gdp_mean
1 NA
Can anyone tell me what I'm doing wrong, please?
r dplyr
I'm trying to take the mean of some data with NA values, and I would like the NA values to be ignored. A reproducible example would be:
country gdp
1 Austria 25.17
2 Azerbaijan NA
3 Bangladesh 27.79
4 Belarus NA
testdf2 <- data.frame(stringsAsFactors=FALSE,
country = c("Austria", "Azerbaijan", "Bangladesh", "Belarus"),
gdp = c(25.17654, NA, 27.7971, NA)
)
I've tried summarise()
using rm.na = TRUE
and without
library(dplyr)
testdf2 %>% summarise(gdp_mean = mean(gdp))
testdf2 %>% summarise(gdp_mean = mean(gdp), rm.na = TRUE)
but I keep getting output that looks like this:
gdp_mean
1 NA
Can anyone tell me what I'm doing wrong, please?
r dplyr
r dplyr
asked Mar 6 at 15:28
RAndStataRAndStata
222112
222112
2
testdf2 %>% summarise(gdp_mean = mean(gdp, na.rm= TRUE))
– Wen-Ben
Mar 6 at 15:30
1
rm.na = TRUE
should bemean
argument and notsummarise
, so:mean(gdp, rm.na = TRUE)
– kwiscion
Mar 6 at 15:30
add a comment |
2
testdf2 %>% summarise(gdp_mean = mean(gdp, na.rm= TRUE))
– Wen-Ben
Mar 6 at 15:30
1
rm.na = TRUE
should bemean
argument and notsummarise
, so:mean(gdp, rm.na = TRUE)
– kwiscion
Mar 6 at 15:30
2
2
testdf2 %>% summarise(gdp_mean = mean(gdp, na.rm= TRUE))
– Wen-Ben
Mar 6 at 15:30
testdf2 %>% summarise(gdp_mean = mean(gdp, na.rm= TRUE))
– Wen-Ben
Mar 6 at 15:30
1
1
rm.na = TRUE
should be mean
argument and not summarise
, so: mean(gdp, rm.na = TRUE)
– kwiscion
Mar 6 at 15:30
rm.na = TRUE
should be mean
argument and not summarise
, so: mean(gdp, rm.na = TRUE)
– kwiscion
Mar 6 at 15:30
add a comment |
1 Answer
1
active
oldest
votes
I think you made a typo. I tried your code like this and it works: rm.na
should be na.rm
, and of course what @kwiscion mentioned in his comment!
testdf2 %>% summarise(gdp_mean = mean(gdp, na.rm = TRUE))
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%2f55026656%2fna-values-causing-problems-in-summarise-even-when-using-rm-na-true%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
I think you made a typo. I tried your code like this and it works: rm.na
should be na.rm
, and of course what @kwiscion mentioned in his comment!
testdf2 %>% summarise(gdp_mean = mean(gdp, na.rm = TRUE))
add a comment |
I think you made a typo. I tried your code like this and it works: rm.na
should be na.rm
, and of course what @kwiscion mentioned in his comment!
testdf2 %>% summarise(gdp_mean = mean(gdp, na.rm = TRUE))
add a comment |
I think you made a typo. I tried your code like this and it works: rm.na
should be na.rm
, and of course what @kwiscion mentioned in his comment!
testdf2 %>% summarise(gdp_mean = mean(gdp, na.rm = TRUE))
I think you made a typo. I tried your code like this and it works: rm.na
should be na.rm
, and of course what @kwiscion mentioned in his comment!
testdf2 %>% summarise(gdp_mean = mean(gdp, na.rm = TRUE))
answered Mar 6 at 15:31
ricoderksricoderks
585210
585210
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%2f55026656%2fna-values-causing-problems-in-summarise-even-when-using-rm-na-true%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
2
testdf2 %>% summarise(gdp_mean = mean(gdp, na.rm= TRUE))
– Wen-Ben
Mar 6 at 15:30
1
rm.na = TRUE
should bemean
argument and notsummarise
, so:mean(gdp, rm.na = TRUE)
– kwiscion
Mar 6 at 15:30