Mostly, tbl
(tibbles) are the same as data.frame
s, except they don’t print all lines. When subsetting only one column using brackets, a data.frame
will return a vector, but a tbl
will return a tbl
df[, 1]
[1] "Mazda RX4" "Mazda RX4 Wag" "Datsun 710"
[4] "Hornet 4 Drive" "Hornet Sportabout" "Valiant"
[7] "Duster 360" "Merc 240D" "Merc 230"
[10] "Merc 280" "Merc 280C" "Merc 450SE"
[13] "Merc 450SL" "Merc 450SLC" "Cadillac Fleetwood"
[16] "Lincoln Continental" "Chrysler Imperial" "Fiat 128"
[19] "Honda Civic" "Toyota Corolla" "Toyota Corona"
[22] "Dodge Challenger" "AMC Javelin" "Camaro Z28"
[25] "Pontiac Firebird" "Fiat X1-9" "Porsche 914-2"
[28] "Lotus Europa" "Ford Pantera L" "Ferrari Dino"
[31] "Maserati Bora" "Volvo 142E"
tbl[, 1]
# A tibble: 32 x 1
car
<chr>
1 Mazda RX4
2 Mazda RX4 Wag
3 Datsun 710
4 Hornet 4 Drive
5 Hornet Sportabout
6 Valiant
7 Duster 360
8 Merc 240D
9 Merc 230
10 Merc 280
# ... with 22 more rows
tbl[, "mpg"]
# A tibble: 32 x 1
mpg
<dbl>
1 21
2 21
3 22.8
4 21.4
5 18.7
6 18.1
7 14.3
8 24.4
9 22.8
10 19.2
# ... with 22 more rows
df[, 1, drop = FALSE]
mpg
1 Mazda RX4
2 Mazda RX4 Wag
3 Datsun 710
4 Hornet 4 Drive
5 Hornet Sportabout
6 Valiant
7 Duster 360
8 Merc 240D
9 Merc 230
10 Merc 280
11 Merc 280C
12 Merc 450SE
13 Merc 450SL
14 Merc 450SLC
15 Cadillac Fleetwood
16 Lincoln Continental
17 Chrysler Imperial
18 Fiat 128
19 Honda Civic
20 Toyota Corolla
21 Toyota Corona
22 Dodge Challenger
23 AMC Javelin
24 Camaro Z28
25 Pontiac Firebird
26 Fiat X1-9
27 Porsche 914-2
28 Lotus Europa
29 Ford Pantera L
30 Ferrari Dino
31 Maserati Bora
32 Volvo 142E