tibble

How to pivot a single cell dataframe

非 Y 不嫁゛ 提交于 2021-02-19 12:52:32
问题 I have encountered such a simple challenge, and yet don't know how to do this properly. library(tibble) library(dplyr) # I have this single-cell dataframe tibble::tribble(~red, "apple") ## # A tibble: 1 x 1 ## red ## <chr> ## 1 apple But being red is a property of the variable fruit , which apple is one observation of. Therefore, I want my data to look like: # Desired Output: ## # A tibble: 1 x 2 ## fruit red ## <chr> <lgl> ## 1 apple TRUE So I tried a clunky method, which seems not best

How to pivot a single cell dataframe

↘锁芯ラ 提交于 2021-02-19 12:51:36
问题 I have encountered such a simple challenge, and yet don't know how to do this properly. library(tibble) library(dplyr) # I have this single-cell dataframe tibble::tribble(~red, "apple") ## # A tibble: 1 x 1 ## red ## <chr> ## 1 apple But being red is a property of the variable fruit , which apple is one observation of. Therefore, I want my data to look like: # Desired Output: ## # A tibble: 1 x 2 ## fruit red ## <chr> <lgl> ## 1 apple TRUE So I tried a clunky method, which seems not best

How to pivot a single cell dataframe

本秂侑毒 提交于 2021-02-19 12:49:13
问题 I have encountered such a simple challenge, and yet don't know how to do this properly. library(tibble) library(dplyr) # I have this single-cell dataframe tibble::tribble(~red, "apple") ## # A tibble: 1 x 1 ## red ## <chr> ## 1 apple But being red is a property of the variable fruit , which apple is one observation of. Therefore, I want my data to look like: # Desired Output: ## # A tibble: 1 x 2 ## fruit red ## <chr> <lgl> ## 1 apple TRUE So I tried a clunky method, which seems not best

Is there more efficient or concise way to use tidyr::gather to make my data look 'tidy'?

前提是你 提交于 2021-02-18 16:59:43
问题 I am new to using tidyverse. I want to see if I am being as efficient/concise as possible using the functions in this package. I suspect I am not. My original data has the key sym as part of each column name. day a_x b_x a_y b_y 1 1 -0.56047565 1.2240818 -1.0678237 0.42646422 2 2 -0.23017749 0.3598138 -0.2179749 -0.29507148 ... I would like to make the data look tidy, like so: day sym x y 1 1 a 0.118 0.702 2 2 a -0.947 -0.262 ... 11 1 b 1.44 0.788 12 2 b 0.452 0.769 Here is my code that does

Is there more efficient or concise way to use tidyr::gather to make my data look 'tidy'?

爷,独闯天下 提交于 2021-02-18 16:59:12
问题 I am new to using tidyverse. I want to see if I am being as efficient/concise as possible using the functions in this package. I suspect I am not. My original data has the key sym as part of each column name. day a_x b_x a_y b_y 1 1 -0.56047565 1.2240818 -1.0678237 0.42646422 2 2 -0.23017749 0.3598138 -0.2179749 -0.29507148 ... I would like to make the data look tidy, like so: day sym x y 1 1 a 0.118 0.702 2 2 a -0.947 -0.262 ... 11 1 b 1.44 0.788 12 2 b 0.452 0.769 Here is my code that does

Transform a list column in a tibble to multiple columns after using enframe from {tibble}

▼魔方 西西 提交于 2021-02-08 06:49:58
问题 I have the following list my_list <- list(`3920_0` = structure(c(623700, 96400), .Dim = 1:2, .Dimnames = list("1", c("X", "Y"))), `3864_0` = structure(c(665100, 167400), .Dim = 1:2, .Dimnames = list("1", c("X", "Y"))), `1948_1` = structure(c(589800, 97900), .Dim = 1:2, .Dimnames = list("1", c("X", "Y")))) looking as follows $`3920_0` X Y 1 623700 96400 $`3864_0` X Y 1 665100 167400 $`1948_1` X Y 1 589800 97900 When I use enframe I get the following # A tibble: 3 x 2 name value <chr> <list> 1

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

与世无争的帅哥 提交于 2021-02-07 13:36:53
问题 I have a csv file weight.csv with the following contents. weight,weight_selfreport 81.5,81.66969147005445 72.6,72.59528130671505 92.9,93.01270417422867 79.4,79.4010889292196 94.6,96.64246823956442 80.2,79.4010889292196 116.2,113.43012704174228 95.4,95.73502722323049 99.5,99.8185117967332 If I do library(readr) Df <- read_csv('weight.csv') Df I get # A tibble: 9 x 2 weight weight_selfreport <dbl> <dbl> 1 81.5 81.7 2 72.6 72.6 3 92.9 93.0 4 79.4 79.4 5 94.6 96.6 6 80.2 79.4 7 116. 113. 8 95.4

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

一笑奈何 提交于 2021-02-07 13:36:42
问题 I have a csv file weight.csv with the following contents. weight,weight_selfreport 81.5,81.66969147005445 72.6,72.59528130671505 92.9,93.01270417422867 79.4,79.4010889292196 94.6,96.64246823956442 80.2,79.4010889292196 116.2,113.43012704174228 95.4,95.73502722323049 99.5,99.8185117967332 If I do library(readr) Df <- read_csv('weight.csv') Df I get # A tibble: 9 x 2 weight weight_selfreport <dbl> <dbl> 1 81.5 81.7 2 72.6 72.6 3 92.9 93.0 4 79.4 79.4 5 94.6 96.6 6 80.2 79.4 7 116. 113. 8 95.4

How to write a function in R that will implement the “best subsets” approach to model selection?

耗尽温柔 提交于 2021-01-29 19:03:47
问题 So I need to write a function that takes a data-frame as input. The columns are my explanatory variables (except for the last column/right most column which is the response variable). I'm trying to fit a linear model and track each model's adjusted r-square as the criterion used to pick the best model. The model will use all the columns as the explanatory variables (except for the right-most column which will be the response variable). The function is supposed to create a tibble with a single

Self Joining in R

淺唱寂寞╮ 提交于 2021-01-28 21:06:13
问题 Here is a sample tibble: test <- tibble(a = c("dd1","dd2","dd3","dd4","dd5"), name = c("a", "b", "c", "d", "e"), b = c("dd3","dd4","dd1","dd5","dd2")) And I want to add a new column b_name as self-join to test using: dplyr::inner_join(test, test, by = c("a" = "b")) My table is way to large (2.7M rows with 4 columns) and I get the following error: Error: std::bad_alloc Please advise how to do it right / best practice. My final goal is to get the following structure: a name b b_name dd1 a dd3 c