In R, using melt(), how can I hide warning messages?

隐身守侯 提交于 2020-12-26 06:54:24

问题


I'm melting some data and don't want to provide an id.var parameter to melt. The data melts fine, but I get the

"No id variables; using all as measure variables"

Is there a way to prevent that message from coming up, or a way to say id.var=default or something like that? An iris example using dplyr:

> dt <- iris %>% summarize_at(c("Sepal.Length","Sepal.Width"), funs(mean))
> dt
  Sepal.Length Sepal.Width
1     5.843333    3.057333
> melt(dt, value.name="Mean")
No id variables; using all as measure variables
      variable     Mean
1 Sepal.Length 5.843333
2  Sepal.Width 3.057333

Alternatively is there a way to tell a function to not print warning messages or something like that? Thanks!


回答1:


Strictly speaking, this is a message, not a warning. (see ?message and ?warning). You can suppress messages with suppressMessages

suppressMessages({
  reshape2::melt(head(mtcars))
})

For melt specifically, you may use id.vars = NULL. (with credit to @user20650)



来源:https://stackoverflow.com/questions/48774207/in-r-using-melt-how-can-i-hide-warning-messages

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!