na Questions

7

Solved

I have a data frame containing (in random places) a character value (say "foo") that I want to replace with a NA. What's the best way to do so across the whole data frame?
Ornithischian asked 28/7, 2010 at 21:42

2

Solved

I have a factor that I'm using as a lookup table. condLookup = c(hotdog = "ketchup", ham = "mustard", popcorn = "salt", coffee = "cream") This works as expe...
Ytterbium asked 21/6, 2020 at 19:36

2

Solved

I have the following data.frame: x <- data.frame(A = c("Y", "Y", "Z", NA), B = c(NA, TRUE, FALSE, TRUE), C = c(TRUE, TRUE, NA, FALSE)) And I need to compute the following table with xtabs: ...
Baylor asked 15/4, 2020 at 23:6

3

Solved

I have a big data.frame called "mat" of 49952 obs. of 7597 variables and I'm trying to replace NAs with zeros. Here is and example how my data.frame looks like: A B C E F D Q Z . . . 1 1 1 0 NA N...
Craving asked 8/8, 2017 at 17:6

1

Solved

I'm using kaggle's pokemon data to practice KNN imputation via preProcess(), but when I did I encountered this following message after the predict() step. I am wondering if I use the incorrect data...
Arbogast asked 29/5, 2020 at 12:19

4

Solved

Quick question. I read my csv file into the variable data. It has a column label var, which has numerical values. When I run the command sd(data$var) I get [1] NA instead of my standard d...
Frieze asked 21/4, 2011 at 4:28

7

I've been encountering what I think is a bug. It's not a big deal, but I'm curious if anyone else has seen this. Unfortunately, my data is confidential, so I have to make up an example, and it's no...
Fusee asked 10/1, 2013 at 15:42

4

My data looks like this: https://i.sstatic.net/zXk8a.jpg I want to change the values NA to another value for each column. For example in the column that contains NA, Single and Dual, I want to ch...
rna
Guthry asked 11/1, 2016 at 10:7

6

Solved

I want to replace <NA> values in a factors column with a valid value. But I can not find a way. This example is only for demonstration. The original data comes from a foreign csv file I have ...
Millisent asked 24/8, 2016 at 14:46

2

Solved

How can I pass an NA value from Rcpp to R in a 64 bit vector? My first approach would be: // [[Rcpp::export]] Rcpp::NumericVector foo() { Rcpp::NumericVector res(2); int64_t val = 12345678901...
Mu asked 23/4, 2020 at 11:35

5

Solved

I have a df as follows which has 20 people across 5 households. Some people within the household have missing data for whether they have a med_card or not. I want to give these people the same valu...
rna
Katalin asked 10/5, 2014 at 16:42

4

Solved

Here is my toy dataset df <- tribble( ~x, ~y, ~z, 7, NA, 4, 8, 2, NA, NA, NA, NA, NA, 4, 6) I want to get a dataframe with a number of NAs for each variable only between the first and th...
Mada asked 12/2, 2020 at 13:28

3

Solved

I have used the same method for replacing NA's with blanks or other characters but for some reason this one is not working. I want to replace the NA's on my dataframe to blanks (columns year and An...
Instauration asked 28/1, 2020 at 19:13

4

Solved

This line: which(!is.na(c(NA,NA,NA))) == 0 produces logical(0) While this line if(which(!is.na(c(NA,NA,NA))) == 0){print('TRUE')} generates: Error in if (which(!is.na(c(NA, NA, NA))) == 0)...
Robber asked 5/2, 2018 at 15:42

5

Solved

Suppose you have a dataframe with 9 columns. You want to remove cases which have all NAs in columns 5:9. It's not at all relevant if there are NAs in columns 1:4. So far I have found functions tha...
Harslet asked 30/7, 2018 at 14:47

3

Solved

I have some data that I am looking at in R. One particular column, titled "Height", contains a few rows of NA. I am looking to subset my data-frame so that all Heights above a certain value are e...
Ferdy asked 6/11, 2016 at 5:2

6

Solved

edit The question was originally asked for data.table. A solution with any package would be interesting. I am a little stuck with a particular variation of a more general problem. I have panel d...
Responsive asked 8/12, 2014 at 23:13

3

Solved

I need to delete rows containing NA, but only if they are leading(trailing) i.e. before(after) any data appears for a variable. This is very similar to: How to find (not replace) leading NAs, gap...
Unionism asked 26/10, 2019 at 10:52

10

Solved

I have some columns in R and for each row there will only ever be a value in one of them, the rest will be NA's. I want to combine these into one column with the non-NA value. Does anyone know of a...
Livvy asked 28/1, 2013 at 13:52

4

Solved

I have a sample dataset which looks something similar to the one below: d= data.frame(a = c(1,5,56,4,9), b = c(0,0,NA,0,NA), c = c(98,67,NA,3,7), d = c(0,0,0,0,0), e = c(NA,NA,NA,NA,NA)) ...
Showily asked 24/9, 2019 at 20:20

5

Solved

I have some vectors in the following format v1 <- c(NA,NA,NA,10,10,10,10) v2 <- c(NA,NA, 3, 3, 3,NA,NA) v3 <- c( 5, 5, NA,NA,NA,NA,NA) For each vector I want to calculate how many le...
Dendrology asked 15/9, 2019 at 15:46

3

Solved

This question is related to a post with a similar title (replace NA in an R vector with adjacent values). I would like to scan a column in a data frame and replace NA's with the value in the adjace...
Attitude asked 26/3, 2013 at 5:18

4

Solved

I have a dataset that looks like this: before = data.frame(diag1 = c(1,NA, 1, NA, NA, 1), diag2 = c(NA, NA, NA, 2, NA, NA), diag3 = c(3, NA, NA, NA, 3, 3), diag4 = c(4, 4, NA, NA, 4, NA)) diag1...
Deliladelilah asked 11/9, 2019 at 17:21

4

Solved

I'm trying to write a function that turns empty strings into NA. A summary of one of my column looks like this: a b 12 210 468 I'd like to change the 12 empty values to NA. I also have a few...
Libidinous asked 2/11, 2016 at 11:38

2

While trying to convert a column of characters (strings of numbers, e.g "0.1234") into numeric, using as.numeric, some of the values are returned NA with the warning 'NAs introduced by coercion'. T...
rna
Maurer asked 26/8, 2019 at 10:21

© 2022 - 2024 — McMap. All rights reserved.