문제

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))
도움이 되었습니까?

해결책

This should work:

x[x==0] <- NA
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top