Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace 0s with NA in tables

Tags:

r

na

I generally work with dataframes and could easily do this for a data frame but on my current project I have the need to replace all zeros with NAs in a table structure. For the following two tables (one using table and the other using ftable) how could I replace all zero counts with NA?

x <- with(mtcars,table(am, gear, cyl, vs))

x2 <- with(mtcars,ftable(am, gear, cyl, vs))
like image 368
Tyler Rinker Avatar asked Mar 22 '12 13:03

Tyler Rinker


1 Answers

This should work:

x[x==0] <- NA
like image 55
nico Avatar answered Sep 18 '22 23:09

nico