Questions tagged [tibble]

tibble could refer to an R class (tbl_df class), which is an improved data frame with stricter checking and better formatting. tibble could also refer to an R package providing functions to create and manipulate a tibble.

1309 questions
59
votes
6 answers

Initialize an empty tibble with column names and 0 rows

I have a vector of column names called tbl_colnames. I would like to create a tibble with 0 rows and length(tbl_colnames) columns. The best way I've found of doing this is... tbl <- as_tibble(data.frame(matrix(nrow=0,ncol=length(tbl_colnames))) and…
colorlace
  • 816
  • 2
  • 10
  • 17
41
votes
6 answers

Unnest a list column directly into several columns

Can I unnest a list column directly into n columns? The list can be assumed to regular, with all elements being of equal length. If instead of a list column I would have a character vector, I could tidyr::separate. I can tidyr::unnest, but we need…
Axeman
  • 32,068
  • 8
  • 81
  • 94
33
votes
3 answers

Add row in each group using dplyr and add_row()

If I add a new row to the iris dataset with: iris <- as_tibble(iris) > iris %>% add_row(.before=0) # A tibble: 151 × 5 Sepal.Length Sepal.Width Petal.Length Petal.Width Species
Dan
  • 1,711
  • 2
  • 24
  • 39
24
votes
3 answers

Having trouble viewing more than 10 rows in a tibble

First off - I am a beginner at programming and R, so excuse me if this is a silly question. I am having trouble viewing more than ten rows in a tibble that is generated from the following code. The code below is meant to find the most common words…
Meraj Shah
  • 243
  • 1
  • 2
  • 4
17
votes
7 answers

How to replace NA with set of values

I have the following data frame: library(dplyr) library(tibble) df <- tibble( source = c("a", "b", "c", "d", "e"), score = c(10, 5, NA, 3, NA ) ) df It looks like this: # A tibble: 5 x 2 source score 1 a 10 . #…
littleworth
  • 4,781
  • 6
  • 42
  • 76
16
votes
2 answers

Controlling decimal places displayed in a tibble. Understanding what pillar.sigfig does

I have a csv file weight.csv with the following…
mjandrews
  • 2,392
  • 4
  • 22
  • 39
16
votes
1 answer

Transform tibble to data frame with column headers

I have data from an excel sheet imported like this: F4_Off <- readxl::read_xlsx("myExcel.xlsx", sheet = "Offline", col_names = TRUE, range = "I1:L285") F4_Off F4_On <- readxl::read_xlsx("myExcel.xlsx", sheet = "Online", col_names = TRUE, range =…
xBarns
  • 291
  • 1
  • 3
  • 12
16
votes
1 answer

Disable pillar formatting for tibble printing

From version 1.4.1, tibble print method seems to be using additional formatting implemented by the pillar package (https://rdrr.io/cran/tibble/f/NEWS.md). The latter tries to output as many columns as possible, shortening some of the values. Is it…
Maxim.K
  • 4,120
  • 1
  • 26
  • 43
16
votes
2 answers

What is the difference between as.tibble(), as_data_frame(), and tbl_df()?

I remember reading somewhere that as.tibble() is an alias for as_data_frame(), but I don't know what exactly an alias is in programming terminology. Is it similar to a wrapper? So I guess my question probably comes down to the difference in possible…
Chill2Macht
  • 1,182
  • 3
  • 12
  • 22
14
votes
1 answer

How to make tibbles display significant digits

I am working with data that has significant digits (i.e. digits after the "."). These digits appear when viewing my data both as a variable in base R, and also when the data is stored in a dataframe. However, they do not appear when I view the data…
Ari
  • 1,819
  • 14
  • 22
14
votes
3 answers

Error in bind_rows_(x, .id) : Column can't be converted from factor to numeric

I have ten datasets that have been read from Excel files, using the xlsx library, and stored in tibbles. I want to merge them. Here are example datasets. The number of variables differ between datasets, and some variables are only in one dataset.…
asterdroid
  • 155
  • 1
  • 2
  • 8
13
votes
2 answers

What are the differences between data.frame, tibble and matrix?

In R, some functions only work on a data.frame and others only on a tibble or a matrix. Converting my data using as.data.frame or as.matrix often solves this, but I am wondering how the three are different ?
Sylvia Rodriguez
  • 1,203
  • 2
  • 11
  • 30
13
votes
1 answer

Which tidyverse functions return tibbles?

Some tidyverse functions return dataframes, but some return tibbles. I can't find any resources on which functions return which data type, and I can't see any real predictable pattern to it. Here are a few examples for…
astrofunkswag
  • 2,608
  • 12
  • 25
13
votes
1 answer

How to exchange Msgpack files between Python and R?

Consider this simple example import pandas as pd mydata = pd.DataFrame({'mytime': [pd.to_datetime('2018-01-01 10:00:00.513'), pd.to_datetime('2018-01-03 10:00:00.513')], 'myvariable': [1,2], …
ℕʘʘḆḽḘ
  • 18,566
  • 34
  • 128
  • 235
13
votes
1 answer

add_column in tibble with variable column name

This code doesn't work to add a column in tibble: library(tidyverse) df <- data.frame("Oranges" = 5) mycols <- c("Apples", "Bananas", "Oranges") add_column(df, mycols[[2]] = 7) I get the error message: Error: unexpected '=' in…
Joe
  • 662
  • 1
  • 7
  • 20
1
2 3
87 88