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
7
votes
1 answer

Replace values in tibble in R 4.0

I just upgraded to R 4.0.0 from R 3.6.2 and some functionality that I use to replace values in a tibble no longer works. I can't find what I need to do now. Does anyone know the "new" way? library(tidyverse) v <- c(1, 2, 3) w <- c(4, 4) i <- 1 #…
zouth0
  • 83
  • 1
  • 6
7
votes
0 answers

Why does mutating a list-column with a single-element list result in a deep copy?

I was unaware that creating a new list-column with dplyr::mutate() with a single-element list actually deep-copies the element to fill the tibble length (see t3). Why is that? If I specify the correct length explicitly (t4) or pass it when creating…
mjktfw
  • 840
  • 6
  • 14
7
votes
1 answer

Convert a "loadings" object to a dataframe (R)

I am trying to convert an object of type "loadings" to a dataframe in R. However, my attempts to coerce it via as_tibble() or as.data.frame() have not worked. Here is the code: iris_pca <- prcomp(iris[1:4], center = TRUE, scale. =…
Hank Lin
  • 5,959
  • 2
  • 10
  • 17
7
votes
1 answer

R: dplyr::lag throws error when trying to lag characters in tibble

I'm getting the following error in R when I try to use the lag function (from the dplyr library) on a column of characters in a tibble: Error in mutate_impl(.data, dots) : Expecting a single string value: [type=logical; extent=1]. This error…
Kimberly Brink
  • 143
  • 1
  • 5
7
votes
3 answers

Elegant way of adding columns on a specific position in a data frame

I have a data.frame with 3 cols: date, rate, price. I want to add columns that come from a matrix, after rate and before price. df = tibble('date' = c('01/01/2000', '02/01/2000', '03/01/2000'), 'rate' = c(7.50, 6.50, 5.54), 'price' =…
7
votes
2 answers

Convert data frame row to column names

Is there a quick way (part of the tidyverse API perhaps) to turn a row into column names for a data.frame or tibble, somewhat similar to tibble::column_to_rownames? I realize there are many ways to do this, e.g. somewhat clumsily: > df <-…
saladi
  • 3,103
  • 6
  • 36
  • 61
6
votes
3 answers

In RStudio, how to print tibble in quarto/rmarkdown chunk as in console?

When editing quarto/rmarkdown documents, I would like RStudio to display inline tibbles the same way as it does in the console, instead of the paginated default printing. Instead of this: I would much prefer the output from the console: # A tibble:…
Peter H.
  • 1,995
  • 8
  • 26
6
votes
3 answers

Can't add rows to grouped data frames

This is a follow-up question of this How to add a row to a dataframe modifying only some columns. After solving this question I wanted to apply the solution provided by stefan to a larger dataframe with group_by: My dataframe: df <-…
TarJae
  • 72,363
  • 6
  • 19
  • 66
6
votes
1 answer

R gt table formatting: How can I take my long gt table and make it wide?

I would like to take a gt() table and transform it to a "wide" format instead of a "long" format by group level. So for, as an example using the iris data set: library(dplyr) library(gt) iris %>% group_by(Species) %>% …
igutierrez
  • 113
  • 7
6
votes
1 answer

dplyr new version 1.0.0 eliminate tbl_cube function and I found no replace of it

I work with multiple dimensional arrays and when I need to plot I usually convert my data to a tibble through tbl_cube to then plot it with ggplot2. Today the new dplyr 1.0.0 was updated to CRAN, and I found that now tbl_cube is no more available.…
Santiago I. Hurtado
  • 1,113
  • 1
  • 10
  • 23
6
votes
1 answer

mlogit.data() Error: Assigned data `ids` must be compatible with existing data

I have been working hours on that and I simply cannot find any solution to the problem. Hopefully someone here can help. I'm trying to create a personal choice matrix for some data with the following structure: # A tibble: 2,152 x 32 age choice…
Daniel Patkovic
  • 141
  • 1
  • 1
  • 5
6
votes
4 answers

Merge rows in tibble

I'd like to list all Functions my package in a table. So far I extracted all functions and title from the packages help docs library(magrittr) package_info <- library(help = magrittr)$info[[2]] package_info_tbl <- package_info %>% …
Thomas
  • 1,252
  • 6
  • 24
6
votes
5 answers

ifelse() function - refer to the following day

I have a dataframe with 2 columns: the date and the return. df <- tibble( date = lubridate::today() +0:9, return= c(1,2.5,2,3,5,6.5,1,9,3,2)) And now I want to add a third column with an ifelse-condition. If the return on day t is higher than 3.5,…
TobKel
  • 1,293
  • 8
  • 20
6
votes
2 answers

R: dplyr and row_number() does not enumerate as expected

I want to enumerate each record of a dataframe/tibble resulted from a grouping. The index is according a defined order. If I use row_number() it does enumerate but within group. But I want that it enumerates without considering the former…
giordano
  • 2,954
  • 7
  • 35
  • 57
6
votes
2 answers

Combining column values with column names using tidyr unite

I have a data.frame with several columns: set.seed(1) df <- data.frame(cluster=LETTERS[1:4],group=c(rep("m",2),rep("f",2)),point=rnorm(4),err=runif(4,0.1,0.3)) and I'd add another columns which "\n" concatenates all columns of its respective row,…
dan
  • 6,048
  • 10
  • 57
  • 125
1 2
3
87 88