How can I replace a specific value (e.g. -10000) with NA within a big list?

replace certain values with na in r
r replace column values conditionally
replace values in r dplyr
r replace values in dataframe column
replace value in r
r update column values
replace row values in r
replace column values in r

This works for the first list element:

values[[1]][values[[1]]==-10000] <-NA

As I do not want to loop over my thousand list elements I'm looking for a command which does the same for the whole list like:

 values[values==-10000] <-NA

But this does not work for the type list:

Error in values[values == -10000] <- NA : (list) object cannot be coerced to type 'double'

Try using lapply:

lst <- list(v1=-10000, v2=500, v3=c(1,2))
lapply(lst, function(x) ifelse(x==-10000, NA, x))

$v1
 [1] NA

$v2
[1] 500

$v3
[1] 1 2

This approach is also robust even if some of the list elements are not numbers, but are other things, such as vectors. In that case, a vector would not match to your target value, and would not be changed.

pandas.Series.replace, Replace values given in to_replace with value . Values in place. Note: this will modify any other views on this object (e.g. a column from a DataFrame). If to_replace is a dict and value is not a list , dict , ndarray , or Series Fill NA values. to_replace : [str, regex, list, dict, Series, numeric, or None] pattern that we are trying to replace in dataframe. value : Value to use to fill holes (e.g. 0), alternately a dict of values specifying which value to use for each column (columns not in the dict will not be filled). Regular expressions, strings and lists or dicts of such objects

As you mention "big list" I provide a second option that uses replace instead which is a bit quicker compared to ifelse.

Thanks to @TimBiegeleisen for the data

lst <- list(v1=-10000, v2=500, v3=c(1,2))
lapply(lst, function(x) replace(x, x == -10000, NA))
#$v1
#[1] NA
#
#$v2
#[1] 500
#
#$v3
#[1] 1 2

benchmark

l <- rep(lst, 100000)
library(microbenchmark)
benchmark <- microbenchmark(
  tim = lapply(l, function(x) ifelse(x==-10000, NA, x)),
  markus = lapply(l, function(x) replace(x, x==-10000, NA))
)

autoplot(benchmark) 

benchmark
#Unit: milliseconds
#   expr      min        lq      mean    median        uq      max neval cld
#    tim 931.5551 1003.0364 1054.7647 1018.7956 1082.3210 2536.373   100   b
# markus 432.3821  473.9881  500.4833  482.5838  515.9907 1023.392   100  a 

Replace all 0 values to NA, NA is a logical constant of length 1 which contains a missing value indicator. Now you could replace zeroes by NULL in a data frame in the sense of completely When using, e.g., var , cov , or cor , that is actually equivalent to first replacing Table version of this, and because the given data.frame solution does not work  I can create 1 dependant list using the INDIRECT formula without problem but I cannot get any additional lists created that are dependent on the first selection due to not being able to define the names in the same way, i.e. select UK as country then the next list is defined by UK but I cannot create a third due to not being able to name

Using na_if with map

library(tidyverse)
map(lst, na_if, y = -10000)
#$v1
#[1] NA

#$v2
#[1] 500

#$v3
#[1] 1 2
data
lst <- list(v1=-10000, v2=500, v3=c(1,2))

Microsoft Encarta College Dictionary: The First Dictionary For The , mail slot n a narrow opening in a door through which a mail carrier can push envelopes, or something that plays the most important role in a particular group​, place, values that are most widely accepted by a group or society, e.g., in politics, a reasonable standard of living o Site maintains a big family on a tight budget. The code using "within" works well. How can I use dplyr if needed (as part of a longer mutate / summarise process)? Edit: This is a different scenario from Change value of variable with dplyr. I don't want to blindly assign all matching cells with the same value (e.g., NA). I wanted to pull them from another particular column.

R Find Missing Values (6 Examples for Data Frame, Column & Vector), How to find missing data in R – Identify NA values in vectors, data frames or matrices Example 2: Find missing values in a column of a data frame columns by squared brackets which(is.na(expl_matrix1[ , 2])) # Beside the change from might arise how to count missing values per row, by column, or in a single vector. The dplyr hybridized options are now around 30% faster than the Base R subset reassigns. On a 100M datapoint dataframe mutate_all(~replace(., is.na(.), 0)) runs a half a second faster than the base R d[is.na(d)] <- 0 option.

15 Easy Solutions To Your Data Frame Problems In R, Starting R users often experience problems with this particular data With the data frame, R offers you a great first step by allowing you to store Data frames also have similarities with lists, which are basically collections of components. Note that if you change one of the values in the vector Age that this  Products in this category that do provide carbohydrate are often flavored with alternative sweeteners (e.g., sucralose, acesulfame potassium, sorbitol and stevia). The electrolyte-specific capsules are useful during longer-duration exercise sessions and competitions in a hot environment, particularly for individuals who have a high sodium sweat

[PDF] Base R Cheat Sheet, separated value file. This is a Programming. For Loop for (variable in sequence​){. Do something. } Example for (i in 1:4){ a == b. Are equal a > b Greater than a >= b. Greater than or equal to is.na(a) Download and install a package from CRAN. A special case of a list where all elements are the same length. t.test(x, y). We can corroborate this by the definition of those columns and the domain knowledge that a zero value is invalid for those measures, e.g. a zero for body mass index or blood pressure is invalid. Download the dataset from here and save it to your current working directory with the file name pima-indians-diabetes.csv .