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
12
votes
3 answers

How to add metadata to a tibble

How does one add metadata to a tibble? I would like a sentence describing each of my variable names such that I could print out the tibble with the associated metadata and if I handed it to someone who hadn't seen the data before, they could make…
AdrieStC
  • 389
  • 4
  • 13
11
votes
3 answers

Setting row names on a tibble is deprecated. Error: invalid 'row.names' length

I am trying to make a heatmap of a sites vs. species abundances matrix. With thanks to Maurits Evers for some of this code, I am still not able to run it without the error message: Setting row names on a tibble is deprecated.Error in …
chloep
  • 139
  • 1
  • 2
  • 10
11
votes
1 answer

Why does as_tibble() round floats to the nearest integer?

When using as_tibble in dplyr 0.7.4 and R 3.4.1 I get the following outputs mtcars %>% aggregate(disp ~ cyl, data=., mean) %>% as_tibble() which outputs # A tibble: 3 x 2 cyl disp 1 4.00 105 2 6.00 183 3 8.00 …
mickkk
  • 1,172
  • 2
  • 17
  • 38
11
votes
6 answers

How do I do a rolling cumsum over consecutive rows of a tibble in R

I have a toy example of a tibble. What is the most efficient way to sum two consecutive rows of y grouped by x library(tibble) l = list(x = c("a", "b", "a", "b", "a", "b"), y = c(1, 4, 3, 3, 7, 0)) df <- as_tibble(l) df #> # A tibble: 6 x 2 #> …
pssguy
  • 3,455
  • 7
  • 38
  • 68
10
votes
1 answer

Is there way to pivot_longer to multiple values columns in R?

I'm trying to use pivot_longer to enlongate my dataframe, but I don't need it to be fully long, and would like to output multiple "values" columns. Example: df <- tibble( ids = c("protein1", "protein2"), mean.group1 = sample(1:1000, 2), …
jbandura
  • 127
  • 1
  • 6
9
votes
2 answers

What can a data frame do that a tibble cannot?

Fans of the Tidyverse regularly give several advantages of using tibbles rather than data frames. Most of them seem designed to protect the user from making mistakes. For example, unlike data frames, tibbles: Don't need a ,drop=FALSE argument to…
J. Mini
  • 1,868
  • 1
  • 9
  • 38
9
votes
3 answers

Pivoting wide to long format and then nesting columns

I'm given data that comes in a wide format. Each row pertains to a variable external to the current table, and possible values relevant for that variable. I'm trying to: (1) pivot to long format, and (2) nest pivoted values. Example…
Emman
  • 3,695
  • 2
  • 20
  • 44
9
votes
1 answer

Why should I use `all_of` to select columns?

I'm currently using R and came across the function all_of in the tidyverse. What does this function exists for? It seems like I can use just x at every point where all_of(x) can be used.. Example: library(tidyverse) tb <- tibble(a=1:3, b=1:3,…
s1624210
  • 627
  • 4
  • 11
9
votes
5 answers

Create empty tibble/data frame with column names coming from a vector

I would like to create an empty data frame where the column names are coming from a character vector. for example, if this was my vector: vec <- letters[1:3] I would like create an empty data frame like the following: df <- tibble('a' =…
pd441
  • 2,644
  • 9
  • 30
  • 41
9
votes
3 answers

Joining two data frames with intervals misbehaves?

Edit (2019-06): This problem does not exist anymore, as this issue has been closed and a related feature implemented. If you now run the code with updated packages, it will work. I'm trying to find overlapping intervals and decided to join the…
pasipasi
  • 1,176
  • 10
  • 8
8
votes
1 answer

Dplyr warns: `...` is not empty

A new warning message appeared today when printing tibbles library(tidyverse) mtcars %>% head %>% as_tibble prints # A tibble: 6 x 11 mpg cyl disp hp drat wt qsec vs am gear carb
tomw
  • 3,114
  • 4
  • 29
  • 51
8
votes
3 answers

How to rename all column names in tibble by passing a character vector?

I have a tibble named X of multiple columns (over 500) which are named in format of "X"+integer. The tibble looks like this. # A tibble: 7,352 x 561 X1 X2 X3 X4 X5 X6
BigGiantHead
  • 113
  • 1
  • 2
  • 7
8
votes
1 answer

R data.table: how to go from tibble to data.table to tibble back?

I use mainly tables in the tibble fromat from tidyverse, but for some steps, I use the data.table package. I want to see what is the best way of converting a data.table back to tibble? I understand that data.table has some clever function setDT and…
Matifou
  • 7,968
  • 3
  • 47
  • 52
7
votes
2 answers

Returning a tibble: how to vectorize with case_when?

I have a function which returns a tibble. It runs OK, but I want to vectorize it. library(tidyverse) tibTest <- tibble(argX = 1:4, argY = 7:4) square_it <- function(xx, yy) { if(xx >= 4){ tibble(x = NA, y = NA) } else if(xx == 3){ …
David T
  • 1,993
  • 10
  • 18
7
votes
3 answers

calculate indices with base year and relative percentage change

I am looking for a way to, within id and groups, create an index on 100 using the lag (or is it lead) of value and the new index number idx_value to calculate the next index number. # install.packages(c("tidyverse"), dependencies =…
Eric Fail
  • 8,191
  • 8
  • 72
  • 128
1
2
3
87 88