Linked Questions
76 questions linked to/from How do I replace NA values with zeros in an R dataframe?
50
votes
3
answers
246k
views
replacing NA's with 0's in R dataframe [duplicate]
I've been playing around with the airquality dataset in R and figuring out how to remove lines with missing values. I used the following command:
complete.cases(airquality)
AQ1<-airquality[...
2
votes
2
answers
15k
views
Replacing all occurrences of a value in a data frame column [duplicate]
How can I replace, for example, all "-sh2", in a column (V2) with -100, as in the following dataframe:
V1 V2 V3
p1 -sh2 13
p2 23 29
p3 17 25
p4 -sh2 34
Thanks
1
vote
1
answer
10k
views
Replace NAs according to conditions [duplicate]
I have a dataset with lots of numerical variables, and a character variables that says whether or not low values are suppressed for that observation. In observations where values aren't suppressed, I ...
1
vote
1
answer
9k
views
How to replace NAs with characters within a df [duplicate]
I want all NAs to be replaced with "Not Found" in a df .
i have this df
A B
1 NA
2 NA
3 NA
How can i get that .
A B
1 Not Found
2 Not Found
3 Not Found
0
votes
3
answers
3k
views
Is there R code to replace empty cells with 0's but keep populated cells with their original value? [duplicate]
I want to replace some empty cells in Variable B and Variable C with 0 if Variable A == 0. If Variable A equals anything but 0 I would like Variable B and Variable C to stay the same. I've created a ...
1
vote
3
answers
2k
views
replacing all NA values in a column with 0 in R using dplyr [duplicate]
merged$number_articles %>% replace_na(0)
Im trying to replace all na values in a column (number_articles) in the df (merged), with 0.
I have tried the above code but the values are not getting ...
0
votes
1
answer
5k
views
Rstudio: how do I replace NA-values with a string type value? [duplicate]
In a dataset of 589 rows there are around 50 entries who miss a variable and are assigned the NA value, but I know which value that should have ("Brussel Hoofstedelijk Gewest" is the exact ...
0
votes
1
answer
3k
views
setting multiple columns NA's to value --R [duplicate]
Quite new to R, I am trying to subselect certain columns in order to set their NA's to 0.
so far I have:
col_names1 <- c('a','b','c')
col_names2 <- c('e','f','g')
col_names <- c(col_names1,...
-2
votes
2
answers
3k
views
how to replace certain word in table in R studio [duplicate]
Recently, I started learning R. I would like to replace certain word in table by other word in the same table.
For example, my table looks like
No. Fruits Weight Size
1 AB 200 L
2 AM 150 M
3 ...
1
vote
1
answer
3k
views
How to do multiple operations, ignoring NAs, in R [duplicate]
Is there a quick way to run multiple arithmetic operations across data frame variables while ignoring cases with NAs? I've put a simple example below.
It seems I could add intermediary variables or '...
-1
votes
3
answers
1k
views
How i can replace zeros with NAs across all columns in R using dplyr? [duplicate]
i have a dataframe that looks like this :
Date = seq(as.Date("2022/1/1"), by = "day", length.out = 10)
x = c(rnorm(9),NA)
y = c(NA,0,rnorm(4),6,0,0,10)
z = c(rnorm(4),0,0,NA,NA,3,2)...
3
votes
1
answer
2k
views
R replace values in dataframe [duplicate]
I need to replace some data in my dataframe, which looks like this:
V1 V2 V3 V4
1 * * 4 5
2 * * 4 *
3 4 * 2 2
4 * * 1 *
If a "*" is in that cell, replace it with the value of the ...
0
votes
0
answers
3k
views
R: how to use if myValue.is.na? [duplicate]
Basically, I am iterating through some values, some which may be NA. If it is NA, I'd like to set it to 0.
For example
if (myValue.is.na){
myValue=0
}
1
vote
2
answers
1k
views
Merging data frame and filling missing values [duplicate]
I want to merge the following 3 data frames and fill the missing values with -1. I think I should use the fct merge() but not exactly know how to do it.
> df1
Letter Values1
1 A 1
2 ...
-2
votes
1
answer
2k
views
Change name of a cell in data frame in R [duplicate]
I have a data set:
x y z
1 apple a 4
2 orange d 3
3 banana b 2
4 strawberry c 1
How can I change the name "banana" to "grape"? I want to get:
x y z
1 apple a ...