tibble

Purrr safely creating lists of lists

天大地大妈咪最大 提交于 2020-06-13 09:24:33
问题 I've used safely to catch an error which occurs in my code when I'm purring. However, the result from safely is much more complex than I anticipated. First we create the necessary functions and example data. #base functions. SI_tall <- function(topheight, age, si ){ paramasi <- 25 parambeta <- 7395.6 paramb2 <- -1.7829 refAge <- 100 d <- parambeta*(paramasi^paramb2) r <- (((topheight-d)^2)+(4*parambeta*topheight*(age^paramb2)))^0.5 ## height at reference age h2 <- (topheight+d+r)/ (2+(4

Returning a tibble: how to vectorize with case_when?

北慕城南 提交于 2020-05-26 19:16:34
问题 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){ tibble(x = as.integer(), y = as.integer()) } else if (xx == 2){ tibble(x = xx^2 - 1, y = yy^2 -1) } else { tibble(x = xx^2, y = yy^2) } } It runs OK in a mutate when I call it with map2 , giving me the result I wanted: tibTest %>% mutate(sq = map2(argX, argY, square

Disable pillar formatting for tibble printing

风格不统一 提交于 2020-05-11 04:07:17
问题 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 possible to disable this formatting and go back to the print method that existed before? In some cases, by outputting the extra columns and shortening the values, pillar makes it difficult to read the contents of the first columns, which is often

Unable to run Two-way repeated measures ANOVA; 0 (non-NA) cases

为君一笑 提交于 2020-05-08 14:44:17
问题 I am trying to follow the tutorial by Datanovia for Two-way repeated measures ANOVA. A quick overview of my dataset: I have measured the number of different bacterial species in 12 samplingsunits over time. I have 16 time points and 2 groups. I have organised my data as a tibble called "richness"; # A tibble: 190 x 4 id selection.group Day value <fct> <fct> <fct> <dbl> 1 KRH1 KR 2 111. 2 KRH2 KR 2 141. 3 KRH3 KR 2 110. 4 KRH1 KR 4 126 5 KRH2 KR 4 144 6 KRH3 KR 4 135. 7 KRH1 KR 6 115. 8 KRH2

Finding duplicate observations of selected variables in a tibble

你离开我真会死。 提交于 2020-04-30 07:06:46
问题 I have a rather large tibble (called df.tbl with ~ 26k rows and 22 columns) and I want to find the "twins" of each object, i.e. each row that has the same values in column 2:7 (date:Pos). If I use: inner_join(df.tbl, ~ df.tbl[i,], by = c("date", "forge", "serNum", "PinMain", "PinMainNumber", "Pos")) with i being the row I want to check for "twins", everything is working as expected, spitting out a 2 x 22 tibble, and I can expand this using: x <- NULL for (i in 1:nrow(df.tbl)) { x[[i]] <- as

Row to colnames

佐手、 提交于 2020-02-22 05:59:21
问题 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 <- head(iris) > > df %>% + set_colnames(magrittr::extract(., 1,)) %>% + magrittr::extract(-1,) 5.1 3.5 1.4 0.2 1 2 4.9 3.0 1.4 0.2 setosa 3 4.7 3.2 1.3 0.2 setosa 4 4.6 3.1 1.5 0.2 setosa 5 5.0 3.6 1.4 0.2 setosa 6 5.4 3.9 1.7 0.4 setosa 回答1: janitor::row_to