Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of var_dump() in R?

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);

Yields:

array(2) {
  [0]=>
  int(1)
  ["moo"]=>
  int(2)
}
like image 362
Tor Avatar asked Jan 07 '10 05:01

Tor


People also ask

What is Var_dump () function?

The var_dump() function dumps information about one or more variables. The information holds type and value of the variable(s).

What is the difference between Var_dump () and Print_r ()?

var_dump() displays values along with data types as output. print_r() displays only value as output. It does not have any return type. It will return a value that is in string format.

Is there a Var_dump in JavaScript?

The var_dump equivalent in JavaScript? Simply, there isn't one. Prints an interactive listing of all properties of the object.

Which PHP output displays structured information about variables expressions including their types and values?

The var_dump function displays structured information about variables/expressions including its type and value. Arrays are explored recursively with values indented to show structure.


2 Answers

A few examples:

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

Output on screen:

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 ...
like image 107
Brandon Bertelsen Avatar answered Sep 26 '22 06:09

Brandon Bertelsen


Check out the dump command:

> x <- c(8,6,7,5,3,0,9)
> dump("x", "")
x <-
c(8, 6, 7, 5, 3, 0, 9)
like image 27
Jonathan Chang Avatar answered Sep 25 '22 06:09

Jonathan Chang