Questions tagged [na.rm]

48 questions
1
vote
1 answer

NA value in mean?

Whenever I use df %>% remove_empty(c("rows", "cols")) and then take mean of df using df %>% summarise(mean= mean(value), sd= sd(value), n = length(value)) I get mean= NA sd=NA n= 2000 However, when I use this…
Drake
  • 47
  • 4
1
vote
2 answers

Using summarize across with multiple functions when there are missing values

If I want to get the mean and sum of all the numeric columns using the mtcars data set, I would use following codes: group_by(gear) %>% summarise(across(where(is.numeric), list(mean = mean, sum = sum))) But if I have missing values in some of…
Anup
  • 239
  • 2
  • 11
1
vote
1 answer

`na.rm` is not removing NAs

Unfortunately, na.rm did not remove my NAs and I do not get the wanted result. Here is what I have done: First, I have recoded a column in R to get rid of unnecessary values for my project (and herein probably lies the issue) ESS.subset$stfdem.rc <-…
user15174990
1
vote
0 answers

Can't get na.rm=TRUE to work for function

I am practicing writing functions and testing them. I have written the following functions but when I try to specify na.rm=TRUE my NA's are not being removed. my.mean <- function(x, na.rm) { stopifnot(is.numeric(x)) answer <- sum(x)/length(x) …
snowy
  • 17
  • 2
1
vote
2 answers

Saving na.rm=TRUE for each function in dplyr

I am using dplyr summarise function. My data contain NAs so I need to include na.rm=TRUE for each call. for example: group <- rep(c('a', 'b'), 3) value <- c(1:4, NA, NA) df = data.frame(group, value) library(dplyr) group_by(df, group) %>%…
Rtist
  • 3,825
  • 2
  • 31
  • 40
1
vote
1 answer

na.rm and is.na give different answers

I've just come across a simple problem but I don't understand what's going on. I'm using R to remove NA values and calculate simple summary statistics, but is.na and na.rm are giving me different answers. If I have a vector > test<-c(NA, NA,NA,…
1
vote
1 answer

na.rm and conversion related warnings

Today I tried to finish my last R-study-exercises, but I failed. I`m not allowed to you show the precise instructions of my academic, but you may can help me with the warnings I get after sourcing. What do they mean? What doesn't fit? I know, this…
user1923407
0
votes
0 answers

na.rm while using 'summarize'

While studying tidyverse, I found something cannot understand. The missing data should be excluded with using na.rm = TRUE , so that calculating 'mean' will return a particular value. However, some gropus reveal NaN instead of a number. In library…
0
votes
0 answers

na.rm for a Linear Regression Model

I'm trying to run a linear regression model in R and I want to use na.rm to remove all my missing data. Is it possible to use na.rm here? If so where in the function do I put it? If not, what argument should I use instead? My dataset is called dta…
0
votes
1 answer

adding two variables which has NA present

lets say data is 'ab': a <- c(1,2,3,NA,5,NA) b <- c(5,NA,4,NA,NA,6) ab <-c(a,b) I would like to have new variable which is sum of the two but keeping NA's as follows: desired output: ab$c <-(6,2,7,NA,5,6) so addition of number + NA should equal…
nnet
  • 39
  • 4
0
votes
0 answers

using rollapply function from zoo package in R with na.rm argument

I would like to use the rollapply function from the zoo package in R to calculate a moving IQR, but this fails when missing data (NA's) are reached in my data series. data_series <- c(4,7,4,7,3,6,5,8,5,NA,9,0,5,8,1,3,6,5) roll_iqr <-…
user8229029
  • 883
  • 9
  • 21
0
votes
0 answers

How to debug R code, the issue starts with object 'na.rm' not found; Error in unique(x) : object 'x' not found

Here is my homework: In a first step, describe the dataset as well as the variables contained within it. Use descriptive measures and figures to do this. Then, compare Y T =1 to Y T =0 in a second step. Use an appropriate figure to visualize the…
0
votes
1 answer

R ggplot- na.rm is not removing the record

I am not sure why "na.rm=TRUE" in ggplot() and geom_col() don't remove the missing. Here is the input file (file name in the code is dat.csv…
0
votes
1 answer

Difftime in R with missing times: how to add 'na.rm=TRUE'?

I would like to use difftime() to extract the difference between two date/time variables which are as.posixct. But sometimes one (or both) of the values are missing (NA), just like below. Start time Antibiotic time 2016-06-28 08:36:00 …
Yvonne
  • 21
  • 3
0
votes
1 answer

DescTools :: AUC() trapezoid returns completely different results for na.rm = T and F in a dataset without NA

I have a dataset (alldata) with a time variable for X in hours (Time) and a numeric measurement for Y (Value) for a number of patients with a certain PID (allPID = vector with all PIDs). For the first 24 hours, I want to calculate the area under the…
Denise
  • 3
  • 1