用表中的NA替换0 [英] Replace 0s with NA in tables

查看:105
本文介绍了用表中的NA替换0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常使用数据帧,并且可以轻松地对数据帧执行此操作,但是在我当前的项目中,我需要用表结构中的NA替换所有零.对于以下两个表(一个使用表,另一个使用ftable),如何用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))

推荐答案

这应该有效:

x[x==0] <- NA

这篇关于用表中的NA替换0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆