R 中 xtable 的变量概述
我想知道是否可以通过命令 str(x)
创建一个 xtable
来获取您使用的变量的概述。如果要向某人介绍数据集,这将是一个很好的功能,但自己创建它会很烦人。所以我尝试制作一个像这样的 xtable
:
str(cars)
require(xtable)
xtable(str(cars))
汽车数据集是从 R 给出的。不幸的是 xtable
没有给出 str()< 的 Latexcode /代码>。这里有可能比 R 更聪明吗?以下是
xtable
能够理解的主要命令:
methods(xtable)
有什么想法吗?
I'm wondering if it's possible to create a xtable
from the command str(x)
to get an overview from the variables you use. This would be a nice feature to introduce someone to the dataset, but it's annoying to create it by yourself. So whta I tried is to make a xtable
like this:
str(cars)
require(xtable)
xtable(str(cars))
the cars dataset is given from R. Unfortunately xtable
doesn't give a Latexcode for str()
. Is it possible outsmart R here? Here are the main commands that xtable
will understand:
methods(xtable)
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
另一个值得关注的软件包是
reporttools
。下面是一段简短的代码,用于说明其在reshape
包中的tips
数据集上的用法。这两个摘要语句都会生成乳胶代码,可以将其复制粘贴到文档中,或用于编织。编辑。如果您确实必须使用
str
,那么这是一种解决方法REPORTTOOLS 的输出:
Another package to look at is
reporttools
. Here is an short piece of code to illustrate its usage on thetips
dataset fromreshape
package. Both the summary statements produce latex code which can be copy pasted into a document, or used for weaving.EDIT. If you really MUST use
str
, then here is one way to go about itOUTPUT FROM REPORTTOOLS:
如果您愿意花一些时间研究 Hmisc软件包有效,您很快就会发现有许多实用程序可以促进此类任务。特别是,
contents()
方法通过报告来方便描述data.frame标签和单元的数量可以绑定(在内部,作为
属性
)到每个变量。有关联的
print
、html
和latex
方法用于查看和导出。另一个不错的功能是
describe()
函数,如下所示:If you're willing to spend some time investigating how the Hmisc package works, you will soon discover that there are many utilities that facilitate such tasks. In particular, the
contents()
method facilitates the description of data.frame by reportingLabels and units can be binded (internally, as
attributes
) to each variable.There are associated
print
,html
andlatex
methods for viewing and exporting.Another nice functionality is the
describe()
function, as seen below:由于
xtable
在与data.frames
和matrix
对象一起使用时提供最佳结果,因此我推荐如下内容:抱歉输出过长。您可以在此处获取 PDF。
each
是一个非常通用的函数,因为您可以非常轻松地定义自定义摘要。此外,str 将输出返回到 stdout,因此您无法检索特定变量的摘要。在这种情况下,sapply
将简化结果,生成matrix
而不是data.frame
。但这并不是什么问题,对吧?Since
xtable
provides best result when used withdata.frames
andmatrix
objects, I'd recommend something like this:Sorry for lengthy output. You can grab PDF here.
each
is a very versatile function, since you can define custom summary quite easy. Besides,str
returns output to stdout, so you can't retrieve summary for specific variables. In this case,sapply
will simplify the result, yieldingmatrix
insteaddata.frame
. But that's not so problematic, right?你也可以看一下,
You may give a look also,