na Questions

4

Solved

I have a data frame and I need to add another column to it which shows the count of NAs in all the other columns for that row and also the mean of the non-NA values. I think it can be done in dplyr...
Lengel asked 16/2, 2016 at 21:14

6

Solved

I want to substitute NA by 0 in 20 columns. I found this approach for 2 columns, however I guess it's not optimal if the number of columns is 20. Is there any alternative and more compact solution?...
rna
Aragonite asked 11/10, 2015 at 16:46

3

Solved

I am working with the cancer registry data. In the following data example (ex_data), variables id and diagnosis_yr stand for ID and year at cancer diagnosis receptively. Columns x_2005 to x_2010 an...
Colporteur asked 24/8, 2021 at 19:43

4

I have a DF like Now I want to replace The Col B = NA with 15 since that is the missing value. Col C first NA with 14 and second NA with 15. Col D first NA with 13, second NA with 14 and third NA ...
Abode asked 6/8, 2021 at 3:28

4

Solved

Suppose that we have the following data frame: > dataset1 x 1 1 2 2 3 3 4 NA 5 5 I want to come up with a R command that computes the row index of the 1-column data frame that contains ...
Practically asked 10/11, 2013 at 21:45

5

Solved

there is a dataframe as blow(with NA values) md <- data.frame(cat=c('a','b','d',NA,'E',NA), subcat=c('A','C',NA,NA,NA,'D')) cat subcat 1 a A 2 b C 3 d <NA> 4 <NA> <NA&gt...
rna
Slayton asked 12/6, 2021 at 0:29

4

Solved

For the following sample data dat, is there a way to calculate min and max while handling NAs. My input is: dat <- read.table(text = "ID Name PM TP2 Sigma 1 Tim 1 2 3 2 Sam 0 NA 1 3 Pam ...
Tremor asked 8/6, 2021 at 11:3

6

Solved

I have a data frame with many columns and many rows. col_1 | col_2 | ... | col_n 35 | NA | ... | 2 . | . | . | . . | . | . | . . | . | . | . 123 | 90 | ... | NA Some rows contain NA values (c...
Shortcake asked 5/6, 2021 at 13:54

3

Solved

I need to find the max and min value in a dataframe "df" like this: col1 col2 col3 7 4 5 2 NA 6 3 2 4 NA NA 1 The result should be: min = 1 and max = 7. I have used this function: m...
Gaultiero asked 23/5, 2021 at 19:57

5

Solved

I want to omit rows where NA appears in both of two columns. I'm familiar with na.omit, is.na, and complete.cases, but can't figure out how to use these to get what I want. For example, I have th...
rna
Autonomy asked 5/8, 2014 at 17:16

3

Solved

When I use filter from the dplyr package to drop a level of a factor variable, filter also drops the NA values. Here's an example: library(dplyr) set.seed(919) (dat <- data.frame(var1 = factor(...
Chartulary asked 2/10, 2015 at 13:45

4

Solved

I am trying to create a model using glmnet, (currently using cv to find the lambda value) and I am getting an error NA/NaN/Inf in foreign function call (arg 5). I believe this has something to do w...
Ballou asked 18/2, 2014 at 15:27

4

Solved

I have a large data.table object (1M rows and 220 columns) and I want to replace all blanks ('') with NA. I found a solution in this Post, but it's extremely slow for my data table (takes already o...
Ingaingaberg asked 20/7, 2015 at 12:11

6

Solved

I have a data frame with many columns of different types. I would like to replace each column with NA of the corresponding class. for example: df = data_frame(x = c(1,2,3), y = c("a", "b", "c")) ...
Briseno asked 11/12, 2018 at 7:36

9

Solved

I am writing a function, which needs a check on whether (and which!) column (variable) has all missing values (NA, <NA>). The following is fragment of the function: test1 <- data.frame (m...
Watershed asked 4/7, 2012 at 13:32

7

Solved

Is it possible to filter a data.frame for complete cases using dplyr? complete.cases with a list of all variables works, of course. But that is a) verbose when there are a lot of variables and b) i...
Lowrey asked 12/3, 2014 at 13:50

4

Solved

I am trying to exclude rows have missing values (NA) in all columns for that row AND for which all subsequent rows have only missing values (or is the last empty row itself), i.e. I want to remove ...
Falsehood asked 12/1, 2021 at 17:20

2

Solved

I have a data frame dd2 with hundreds of columns and what I need to do is paste all these column values together omitting any NA values. If I do something like this apply(dd2, 1, paste, collapse="...
rna
Kaleena asked 23/12, 2015 at 4:59

2

Solved

I just saw what seemed like a perfectly good question that was deleted and since like the original questioner I couldn't find a duplicate, I'm posting again. Assume that I have a simple matrix ("m...
Chellman asked 5/1, 2016 at 17:3

5

Solved

I have a simple dataframe as such: ID Col1 Col2 Col3 Col4 1 NA NA NA NA 1 5 10 NA NA 1 NA NA 15 20 2 NA NA NA NA 2 25 30 NA NA 2 NA NA 35 40 And I would like to reformat it as such: ID Col1 ...
Judon asked 20/1, 2015 at 1:22

7

Solved

I would like to solve the following problem with dplyr. Preferable with one of the window-functions. I have a data frame with houses and buying prices. The following is an example: houseID year p...
Aleron asked 28/4, 2014 at 11:42

6

Solved

I am trying to find the percentage of NAs in columns as well as inside the whole dataframe: The first method which I have commented gives me zero and the second method which is not commented gives...
Longwise asked 11/5, 2014 at 19:47

2

I am new here and have searched the forum for my problem, but did not find a solution. I have two data frames which I want to merge on a common key field. merge(x ,y ,by.x="a" ,by.y="b" ,all...
Eligibility asked 18/10, 2013 at 14:21

3

Solved

I have a data.table with columns of different data types. My goal is to select only numeric columns and replace NA values within these columns by 0. I am aware that replacing na-values with zero go...
Dempsey asked 23/5, 2016 at 12:53

5

Using R package pheatmap to draw heatmaps. Is there a way to assign a color to NAs in the input matrix? It seems NA gets colored in white by default. E.g.: library(pheatmap) m<- matrix(c(1:100)...
Saccharose asked 19/9, 2014 at 8:52

© 2022 - 2024 — McMap. All rights reserved.