dplyr

Using dplyr summarise with conditions

懵懂的女人 提交于 2021-02-08 06:47:47
问题 I am currently trying to apply the summarise function in order to isolate the relevant observations from a large data set. A simple reproducible example is given here: df <- data.frame(c(1,1,1,2,2,2,3,3,3), as.logical(c(TRUE,FALSE,TRUE,TRUE,TRUE,TRUE,FALSE,TRUE,FALSE)), as.numeric(c(0,5,0,0,0,0,7,0,7))) colnames(df) <- c("ID", "Status", "Price") ID Status Price 1 1 TRUE 0 2 1 FALSE 5 3 1 TRUE 0 4 2 TRUE 0 5 2 TRUE 0 6 2 TRUE 0 7 3 FALSE 7 8 3 TRUE 0 9 3 FALSE 7 I would like to sort the table

Using dplyr summarise with conditions

自闭症网瘾萝莉.ら 提交于 2021-02-08 06:47:08
问题 I am currently trying to apply the summarise function in order to isolate the relevant observations from a large data set. A simple reproducible example is given here: df <- data.frame(c(1,1,1,2,2,2,3,3,3), as.logical(c(TRUE,FALSE,TRUE,TRUE,TRUE,TRUE,FALSE,TRUE,FALSE)), as.numeric(c(0,5,0,0,0,0,7,0,7))) colnames(df) <- c("ID", "Status", "Price") ID Status Price 1 1 TRUE 0 2 1 FALSE 5 3 1 TRUE 0 4 2 TRUE 0 5 2 TRUE 0 6 2 TRUE 0 7 3 FALSE 7 8 3 TRUE 0 9 3 FALSE 7 I would like to sort the table

R - starting and resetting a counting column in R based on condition

≡放荡痞女 提交于 2021-02-08 05:45:18
问题 I would like to thank for all the help already in advance, as the help until now has allowed me go get new ideas/hypotheses on how my data could be analysed. Data structure(list(record_id = c(110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101, 110101,

Splitting single column into four columns and count repeated pattern in R

霸气de小男生 提交于 2021-02-08 05:24:14
问题 Aim of this project is understand how information is acquired while looking into an object. Imagine an object has elements like a , b , c , d , e and f . A person might look at a and move onto to b and so forth. Now, we wish to plot and understand how that person have navigated across the different elements of a given stimuli. I have data that captured this movement in a single column but I need split this into few columns to get the navigation pattern. Please find the example given below. I

R dplyr mutate_at accessing colnames

你离开我真会死。 提交于 2021-02-08 05:21:26
问题 How could one access the column name being processed by dplyr::mutate_at ? Let's say we would like to convert a column of a data frame into factors with levels stored in a separate list. df <- data.frame("C1"=c("A","B","C"), "C2"=c("D","E","F")) df C1 C2 1 A D 2 B E 3 C F lst <- list("C2"=c("F","E","D"), "C3"=c("G","H","I")) lst $C2 [1] "F" "E" "D" $C3 [1] "G" "H" "I" All of the following trigger error or replace all the column values by NA: df %>% mutate_at(vars(C2), function(x) factor(x,

Programming with tidyeval: The mutate function after tidyr::unite(col = !!col)

倾然丶 夕夏残阳落幕 提交于 2021-02-08 04:54:20
问题 So I want to make a function with unite() from tidyr, but it does not seem to work.. library(dplyr, warn.conflicts = FALSE) library(tidyr, warn.conflicts = FALSE) library(stringr, warn.conflicts = FALSE) mtcars %>% as_tibble() %>% select(mpg , cyl) %>% mutate_all(as.character) %>% unite(col = hello, sep = "/") %>% mutate(hello = str_replace(hello, "/", "")) #> # A tibble: 32 x 1 #> hello #> <chr> #> 1 216 #> 2 216 #> 3 22.84 #> 4 21.46 #> 5 18.78 #> 6 18.16 #> 7 14.38 #> 8 24.44 #> 9 22.84 #>

Programming with tidyeval: The mutate function after tidyr::unite(col = !!col)

白昼怎懂夜的黑 提交于 2021-02-08 04:54:09
问题 So I want to make a function with unite() from tidyr, but it does not seem to work.. library(dplyr, warn.conflicts = FALSE) library(tidyr, warn.conflicts = FALSE) library(stringr, warn.conflicts = FALSE) mtcars %>% as_tibble() %>% select(mpg , cyl) %>% mutate_all(as.character) %>% unite(col = hello, sep = "/") %>% mutate(hello = str_replace(hello, "/", "")) #> # A tibble: 32 x 1 #> hello #> <chr> #> 1 216 #> 2 216 #> 3 22.84 #> 4 21.46 #> 5 18.78 #> 6 18.16 #> 7 14.38 #> 8 24.44 #> 9 22.84 #>

Programming with tidyeval: The mutate function after tidyr::unite(col = !!col)

拈花ヽ惹草 提交于 2021-02-08 04:54:06
问题 So I want to make a function with unite() from tidyr, but it does not seem to work.. library(dplyr, warn.conflicts = FALSE) library(tidyr, warn.conflicts = FALSE) library(stringr, warn.conflicts = FALSE) mtcars %>% as_tibble() %>% select(mpg , cyl) %>% mutate_all(as.character) %>% unite(col = hello, sep = "/") %>% mutate(hello = str_replace(hello, "/", "")) #> # A tibble: 32 x 1 #> hello #> <chr> #> 1 216 #> 2 216 #> 3 22.84 #> 4 21.46 #> 5 18.78 #> 6 18.16 #> 7 14.38 #> 8 24.44 #> 9 22.84 #>

Many regressions using tidyverse and broom: Same dependent variable, different independent variables

风格不统一 提交于 2021-02-08 04:50:44
问题 This link shows how to answer my question in the case where we have the same independent variables, but potentially many different dependent variables: Use broom and tidyverse to run regressions on different dependent variables. But my question is, how can I apply the same approach (e.g., tidyverse and broom) to run many regressions where we have the reverse situation: same dependent variables but different independent variable. In line with the code in the previous link, something like: mod

Many regressions using tidyverse and broom: Same dependent variable, different independent variables

佐手、 提交于 2021-02-08 04:49:40
问题 This link shows how to answer my question in the case where we have the same independent variables, but potentially many different dependent variables: Use broom and tidyverse to run regressions on different dependent variables. But my question is, how can I apply the same approach (e.g., tidyverse and broom) to run many regressions where we have the reverse situation: same dependent variables but different independent variable. In line with the code in the previous link, something like: mod