R中的var_dump()等价于什么? [英] What is the equivalent of var_dump() in R?

查看:98
本文介绍了R中的var_dump()等价于什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个函数来转储变量和对象,并提供对数据类型易于理解的解释.例如,在php var_dump中执行此操作.

I'm looking for a function to dump variables and objects, with human readable explanations of their data types. For instance, in php var_dump does this.

$foo = array();
$foo[] = 1;
$foo['moo'] = 2;

var_dump($foo);

收益:

array(2) {
  [0]=>
  int(1)
  ["moo"]=>
  int(2)
}

推荐答案

一些示例:

foo <- data.frame(1:12,12:1) 
foo ## What's inside?
dput(foo) ## Details on the structure, names, and class
str(foo) ## Gives you a quick look at the variable structure

屏幕上的输出:

foo <- data.frame(1:12,12:1)

foo
   X1.12 X12.1
1      1    12
2      2    11
3      3    10
4      4     9
5      5     8
6      6     7
7      7     6
8      8     5
9      9     4
10    10     3
11    11     2
12    12     1

> dput(foo)

structure(list(X1.12 = 1:12, X12.1 = c(12L, 11L, 10L, 9L, 8L, 
7L, 6L, 5L, 4L, 3L, 2L, 1L)), .Names = c("X1.12", "X12.1"), row.names = c(NA, 
-12L), class = "data.frame")

> str(foo)

'data.frame':   12 obs. of  2 variables:
 $ X1.12: int  1 2 3 4 5 6 7 8 9 10 ...
 $ X12.1: int  12 11 10 9 8 7 6 5 4 3 ...

这篇关于R中的var_dump()等价于什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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