A tibble is a data frame in R that has a refined print method that only shows the first 10 rows of a data frame. This makes it much easier to work with large data and prevents R from attempting to display every row of a data frame.
For example, consider the following tibble with 80 rows and 2 columns:
#load dplyr library(dplyr) #make this example reproducible set.seed(1) #create tibble data #view tibble data # A tibble: 80 x 2 a b 1 -0.626 -0.569 2 0.184 -0.135 3 -0.836 1.18 4 1.60 -1.52 5 0.330 0.594 6 -0.820 0.333 7 0.487 1.06 8 0.738 -0.304 9 0.576 0.370 10 -0.305 0.267 # ... with 70 more rows
When we type in the name of the tibble in R, it will only show the first 10 rows by default. However, it does tell us that there are 70 more rows that are not being displayed.
But in some cases you may actually want to see more than just 10 rows of a tibble.
Note: If you’re new to tibbles, a great place to start is the tibbles chapter in R for Data Science.
Print a Specific Number of Rows of a Tibble
You can print a specific number of rows of a tibble by specifying a number in the print() function:
#print first 20 rows of tibble print(data, n=20) # A tibble: 80 x 2 a b 1 -0.626 -0.569 2 0.184 -0.135 3 -0.836 1.18 4 1.60 -1.52 5 0.330 0.594 6 -0.820 0.333 7 0.487 1.06 8 0.738 -0.304 9 0.576 0.370 10 -0.305 0.267 11 1.51 -0.543 12 0.390 1.21 13 -0.621 1.16 14 -2.21 0.700 15 1.12 1.59 16 -0.0449 0.558 17 -0.0162 -1.28 18 0.944 -0.573 19 0.821 -1.22 20 0.594 -0.473 # ... with 60 more rows
You can also use the pipe operator to achieve the same result:
#print first 20 rows of tibble data %>% print(n=20) # A tibble: 80 x 2 a b 1 -0.626 -0.569 2 0.184 -0.135 3 -0.836 1.18 4 1.60 -1.52 5 0.330 0.594 6 -0.820 0.333 7 0.487 1.06 8 0.738 -0.304 9 0.576 0.370 10 -0.305 0.267 11 1.51 -0.543 12 0.390 1.21 13 -0.621 1.16 14 -2.21 0.700 15 1.12 1.59 16 -0.0449 0.558 17 -0.0162 -1.28 18 0.944 -0.573 19 0.821 -1.22 20 0.594 -0.473 # ... with 60 more rows
Print a All Rows of a Tibble
You can print every row of a tibble by specifying n = Inf:
#print all rows of tibble data %>% print(n=Inf) # A tibble: 80 x 2 a b 1 -0.626 -0.569 2 0.184 -0.135 3 -0.836 1.18 4 1.60 -1.52 5 0.330 0.594 6 -0.820 0.333 7 0.487 1.06 8 0.738 -0.304 9 0.576 0.370 10 -0.305 0.267 11 1.51 -0.543 12 0.390 1.21 13 -0.621 1.16 14 -2.21 0.700 15 1.12 1.59 16 -0.0449 0.558 17 -0.0162 -1.28 18 0.944 -0.573 19 0.821 -1.22 20 0.594 -0.473 21 0.919 -0.620 22 0.782 0.0421 23 0.0746 -0.911 24 -1.99 0.158 25 0.620 -0.655 26 -0.0561 1.77 27 -0.156 0.717 28 -1.47 0.910 29 -0.478 0.384 30 0.418 1.68 31 1.36 -0.636 32 -0.103 -0.462 33 0.388 1.43 34 -0.0538 -0.651 35 -1.38 -0.207 36 -0.415 -0.393 37 -0.394 -0.320 38 -0.0593 -0.279 39 1.10 0.494 40 0.763 -0.177 41 -0.165 -0.506 42 -0.253 1.34 43 0.697 -0.215 44 0.557 -0.180 45 -0.689 -0.100 46 -0.707 0.713 47 0.365 -0.0736 48 0.769 -0.0376 49 -0.112 -0.682 50 0.881 -0.324 51 0.398 0.0602 52 -0.612 -0.589 53 0.341 0.531 54 -1.13 -1.52 55 1.43 0.307 56 1.98 -1.54 57 -0.367 -0.301 58 -1.04 -0.528 59 0.570 -0.652 60 -0.135 -0.0569 61 2.40 -1.91 62 -0.0392 1.18 63 0.690 -1.66 64 0.0280 -0.464 65 -0.743 -1.12 66 0.189 -0.751 67 -1.80 2.09 68 1.47 0.0174 69 0.153 -1.29 70 2.17 -1.64 71 0.476 0.450 72 -0.710 -0.0186 73 0.611 -0.318 74 -0.934 -0.929 75 -1.25 -1.49 76 0.291 -1.08 77 -0.443 1.00 78 0.00111 -0.621 79 0.0743 -1.38 80 -0.590 1.87
You can find more R tutorials here.