I have a dataframe which consist of NA values, want to replace that values with zero's?

```> as.data.frame(matrix(sample(c(NA, 1:10), 100, replace = TRUE), 10))
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
1   9 NA  9 NA NA  6  3 NA  6   8
2   8  8  4  6  9  5  9  4 10   7
3  10  7  7 10  3 NA 10 NA  5  10
4   6  6 NA  9 10  1  4  5 NA   2
5   9  3  3  6  7 10  6  3  2   1
6   4  3  2  5  3 NA  7  7  2   4
7   4  1  8  9  5  1  5  8 NA  NA
8   7  5  4 NA  8 10  3  5  9   2
9   4  3  1  5  5  2  8  3  6   2
10  3 10  3  3  5  6  2 NA  3   4```
Apr 10, 2018 1,977 views

It is simple and easy:

`df1<-as.data.frame(matrix(sample(c(NA, 1:10), 100, replace = TRUE), 10))`
```df1[is.na(df1)] <- 0
> df1
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
1   3  7  1  1  9  2  3  8  7   2
2  10  1  0  5  6  3  9  9  5   1
3   2 10  0  4  4  3  8  9  3   8
4   5  7  2  3  9  4  9  8  2   5
5   5  2  2  3  9 10  6  4  3   7
6   2  4  1  1  5  3  6  4  7  10
7   2  0  2  7  2  4  6  6  7   8
8   2  5  0  2 10  4  2  6  1   3
9   0  3  3  6  7  5  3  3  1   1
10  0  7  1  0  2  2  4  9  4   7

Note*: Here random sample has created new values.

```
• 3,750 points

How to replace only set of values in a vector to different values in a dataframe?

If you have a condition using which ...READ MORE

+1 vote

Custom Function to replace missing values in a vector with the mean of values

Try this. lapply(a,function(x){ifelse(is.na(x),mean(a,na.rm = TRUE ...READ MORE

+1 vote

How to count the number of elements with the values in a vector?

Use dplyr function group_by(). > n = as.data.frame(num) > ...READ MORE

How to remove rows with missing values (NAs) in a data frame?

Hi, The below code returns rows without ...READ MORE

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

How to spilt a column of a data frame into multiple columns

it is easily achievable by using "stringr" ...READ MORE

+1 vote

How to sort a data frame by columns in R?

You can use dplyr function arrange() like ...READ MORE