-1

I am reading a CSV file, with one column having many different values, including being empty:

I want to classify the values of this column as either empty or nonempty to make a contingency table, but I am having trouble replacing all my nonempty values with one value to create this table.

Anyone know how this can be done?

  • Welcome to StackOverflow! Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). This will make it much easier for others to help you. – Jaap Jun 23 '16 at 21:20
  • `df[is.na(df)] <- 0`. If you are trying to replace null values, but please do some research. you should find many answers. Good Luck – user5249203 Jun 23 '16 at 21:21

1 Answers1

1
d <- data.frame(x = rnorm(10), y = rnorm(10))
d$x[sample(1:10, 6)] <- ""
d$empty <- 0
d$empty[d$x == ""] <- 1
head(d)
##                   x           y empty
##1                     1.33223669     1
##2                    -0.05709449     1
##3  -2.70615140865084  0.58530658     0
##4  0.609728583911339  0.52399962     0
##5                     0.22826706     1
##6  0.252969256083018  0.35321125     0

table(d$empty)
##0 1 
##4 6 
mkearney
  • 1,266
  • 10
  • 18