Not Available (how to put information in this position) [closed]

0

I need help. I have a dataframe in R with some columns NA (I know it's uninformated column) and would like to add information in that position, but I have no idea how to do this. Need help. Thank you !!

    
asked by anonymous 25.07.2017 / 05:21

2 answers

1

The best way to give an example of data, in this case a data.frame is to use the command dput :

dput(dat)  # postar o output disto

Let's first produce a% example.

set.seed(2174)
dat <- data.frame(X <- rnorm(10),
            A = sample(letters[1:4], 10, TRUE),
            stringsAsFactors = FALSE)
dat$X[c(2,4,7)] <- NA

Now we have everything we need. Suppose we have data.frame for valor .

inx <- is.na(dat$X)
dat$X[inx] <- valor  # 'valor' deve ser numérico
That's all. Simple, is not it?

    
25.07.2017 / 20:36
1

Hello @Bianca, try the coalesce function of the dplyr package. It replaces all NA's with the indicated value, in the example below it is zero:

x <- sample(c(1:5, NA, NA, NA))
dplyr::coalesce(x, 0L)
    
28.07.2017 / 12:12