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

dplyr/r make class spec_tbl_df

I'm trying to run a line of code that reads over 55 columns. 20 of them have distances of the location from other cities. This code looks for the shortest distance and populates a new column with the name of the city that has the shortest distance…
J.Sabree
  • 2,280
  • 19
  • 48
0
votes
2 answers

Create a dataframe with repeated values

I would like to create a tibble which looks like this: # A tibble: 3 x 4 team arsenal chelsea spurs 1 arsenal self london north-london 2 chelsea london self london …
aaaakkkkk
  • 80
  • 5
0
votes
1 answer

R tibble: aggregating by row across specific columns, by column groups

I have data of biological compounds levels of test patients, who are grouped into different groups depending on being administered certain drugs. That is, we have: Columns: Drugs(or groups) A, B and C, where each group has 3 patients (individually…
AndreyIto
  • 954
  • 1
  • 14
  • 35
0
votes
2 answers

apply function across rows for specific columns

I have tibble like: t <- tribble(~name, ~salary, ~weight, "sarah", 90000, 110, "john", 50000, 150, "jones", 70000, 160, ) I wish to divide salary by 1000, and weight (here in pounds) by 2.2,…
AndreyIto
  • 954
  • 1
  • 14
  • 35
0
votes
2 answers

Changing a character into a date format after checking the entry of another column/row

I have a data set with three fields. I would like to replace any row that has 'Annual' in it to an appropriate date. data: df <- structure(list(`Grants Period Month` = c("Annual", "01-2014-12", "Annual", "Annual", "01-2013-06", "Annual"), `Due…
jb12n
  • 463
  • 1
  • 4
  • 18
0
votes
0 answers

Why function needs tibble as an argument even if it is not used inside function?

This code works as intended: my_tbl<-tibble(var1=c("a","a","a"), var2=c("b","b","b")) string_to_match_list<-list("b") my_row<-my_tbl[2,] my_tbl$var2[2]<-match_every_cell_start_and_modify_with_binary(my_tbl, my_row,…
vasili111
  • 6,032
  • 10
  • 50
  • 80
0
votes
1 answer

How to bar plot answers per category in ggplot?

I have a tibble created like this: tibble(district = c(1, 5, 3, 5, 2, 7, 8, 1, 1, 2, 2, 4, 5, 6, 8, 6, 3), housing = c(1, 1, 2, 1, 2, 2, 2, 1, 1, 2, 3, 2, 1, 1, 1, 3, 2)) Now I would like to know how the type of housing is distributed per…
JNab
  • 135
  • 10
0
votes
1 answer

How to rearrange a tibble by rownames

Traditional dataframes support rearrangement of rows by rownames: > df <- data.frame(c1 = letters[1:3], c2 = 1:3, row.names = paste0("x", 1:3)) > df c1 c2 x1 a 1 x2 b 2 x3 c 3 #' If we want, say, row "x3" and "x1": > df[c("x3", "x1"), ] …
foehn
  • 431
  • 4
  • 13
0
votes
2 answers

Pass multiple variables of a tibble to a function using mutate produces NA's?

Please advise, I have the following simple function: mifflin_equation <- function(gender = "M", w_kg = 50, h_cm = 180, age = 40, …
SteveS
  • 3,789
  • 5
  • 30
  • 64
0
votes
2 answers

Get top x% or top n results from a nested tibble

I am tyring to take the top x results from a group of nested data. Adding map(data, slice(seq(n()*0.2))) to the end of the pipe function gives me errors. So I am trying to get the top 20% of each tbl_df and return them. Secondly How can I nest the…
user8959427
  • 2,027
  • 9
  • 20
0
votes
0 answers

R mutate a nested tibble

I would like to join a 2 dimensional tibble to another one as follows: library(tidyverse) set.seed(1) tib1 <- tibble(locid = seq(2)) tib2 <- tibble(x=runif(1), y = x * 2) I've tried the following: tib3 <- tib1 %>% mutate(z = list(tib2)) %>% …
0
votes
0 answers

Go back to .name_repair result before update to read_xlsx?

I am using the read_xlsx() function in the readxl package, though I think this applies to more functions. I believe an update to the package has made changes to the default for the .name_repair option in the function, and I'm wondering if I can do…
0
votes
1 answer

How to multiply two tibbles with different dimensions in R?

When I multiply a vector by a matrix I do: mat <- matrix(c(c(2,3),c(4,5)),2) vec <- c(1,-1) vec * mat I get [,1] [,2] [1,] 2 4 [2,] -3 -5 But when I try to do something similar with tibbles, like library(dplyr) a <- tibble(x =…
sbac
  • 1,897
  • 1
  • 18
  • 31
0
votes
1 answer

How to access a list of tibble to check whether "UTF-8" and run import R

TARGET : Check whether a list of files have same encoding before import and rbind ,if not the same STOP run # files list & check encoding FL_PATH <- list.files(path,pattern = "*.csv",full.name = T) library(readr) lapply(FL_PATH,guess_encoding) # if…
rane
  • 901
  • 4
  • 12
  • 24
0
votes
1 answer

Aggregate a tibble based on a consecutive values in a boolean column

I've got a fairly straight-forward problem, but I'm struggling to find a solution that doesn't require a wall of code and complicated loops. I've got a summary table, df, for an hourly timeseries dataset where each observations belongs to a group. I…
djfinnoy
  • 585
  • 3
  • 13