3,132 questions
8
votes
3
answers
1k
views
Why does is.na(NULL) returns logical(0) and not FALSE?
I have a bug in one of my packages that I do not understand. I have an if() statement that checks for NA. In one case, the vector returned is NULL.
Why is is.na(NULL) returning an empty logical vector ...
2
votes
3
answers
115
views
r - ggplot stacked area plot with NAs using geom_area
I'm creating a stacked area plot showing phytoplankton biovolume over time, and I have one year of missing data. I'd like my plot to show the break in the data as it would using geom_line, but I can't ...
4
votes
2
answers
161
views
Replace NA values in R dataframe across multiple columns using truncated names of other columns [duplicate]
I have the following data frame (example):
myfile <- data.frame(C1=c(1,3,4,5),
C2=c(5,4,6,7),
C3=c(0,1,3,2),
C1_A=c(NA,NA,1,2),
...
0
votes
1
answer
131
views
How to change fill color for NAs in tmap::tmap_options()
I want to develop a tmap::tmap_style() that includes several options, such as "yellow" for the fill color for missing values. I want to produce the following graphics:
World <- tmap::...
2
votes
2
answers
86
views
Fill Gaps By Taking Column Daily Averages
I'm preparing to run Random Forest, but first I need to get my dataset in a form that would be functional for that. As such, I'm trying to fix a few problems with it. I have theoretical solutions, but ...
0
votes
1
answer
159
views
Setting a flag based on two samples' dates
I have written the following code in R which adds a date (dp_date) and creates a flag (dp_flag) in dt.all sample based on columns from data tables dt.all and Info. The issue that I cannot create ...
3
votes
4
answers
101
views
conditional count by group and create a new vector
I want to create a new vector or a new object matching the number of unique id that are not associated with an age variable (missing data).
Please find a MWE below.
df <- data.frame(id=c('a', 'b', '...
6
votes
6
answers
239
views
Replace the last non NA entry of a row with the value from another column
I have a dataset like this:
tdf <- data.frame(
A = c(1, 2, 5, 4),
B = c(NA, 3, 4, 5),
C = c(NA, NA, NA, NA),
D = c(NA, NA, NA, NA),
E = c(10, 20, 30, 40))
And I need to ...
4
votes
6
answers
186
views
How to mark rows with NAs which were replaced by na.approx()?
I have a dataset with multiple columns and more than 60k rows. I am using na.approx() to replace NAs in each column. I would like to identify the rows which had NA and were replaced, something like &...
5
votes
1
answer
95
views
How to handle groups with NA values when using map_dfr and summarize
I am trying to calculate slopes for multiple measures in a grouped dataset using lm() in R. However, some groups have all NA values for certain measures, which causes the following error:
Error in `...
0
votes
2
answers
89
views
R: factor(x, levels, labels) returns unexpected <NA>
I'm not sure how else to describe this problem. I hope someone knows of this issue already.
Reprex:
t_fac <- factor(c("A", "A"))
t_lev <- factor(c("B", "C"...
0
votes
3
answers
90
views
Three matched ID# columns in a single dataframe one of them has NAs that I need to fill in using the existing data in R
I combined two dataframes using two different shared ID columns ("name" and "idA"). One of the datasets had a third ID column that was retained ("idB"). Now I have one ...
1
vote
1
answer
73
views
R: Omit NA values from a data.table
Problem:
omit the NA values in a data.table random_dt.
It can have NA values for any of entire row or column.
Requirement:
Display only those columns and rows which have non NA values including zeroes....
2
votes
1
answer
170
views
Why doesn't scale_shape_manual behave in the same way as scale_color_manual and scale_fill_manual?
Say I have a data frame like myiris below, where I want to just highlight the setosa species.
I don't want, however, the other species to show in the legend. For my convenience, I just made all the ...
1
vote
1
answer
78
views
NA values when running summary statistics for NSCH data in R using mitools and survey packages
I am working with NSCH data for the first time in R. I found the following resource, which has been enormously helpful (thank you!).
https://github.com/ajdamico/asdfree/blob/master/nsch.Rmd
I followed ...