dplyr

Shiny R using input-variables for dynamic dplyr creation of dataTables

不打扰是莪最后的温柔 提交于 2021-02-08 09:55:52
问题 Target: Building a shiny-app which enables the user to make 3 inputs via Groupcheckboxfields: Groupingvariables Metricvariables Statistics which are used in dplyr look at this code first - it is executed without shiny and displays the to be achived results: library("plyr") library("dplyr") ## Without shiny - it works! groupss <- c("gear", "carb") statistics <- c("min", "max", "mean") metrics <- c("drat", "hp") grp_cols <- names(mtcars[colnames(mtcars) %in% groupss]) dots <- lapply(grp_cols,

Insert Column Name into its Value using R

我是研究僧i 提交于 2021-02-08 08:52:38
问题 I need to insert Column Name, Department, into its value. i have code like here: Department <- c("Store1","Store2","Store3","Store4","Store5") Department2 <- c("IT1","IT2","IT3","IT4","IT5") x <- c(100,200,300,400,500) Result <- data.frame(Department,Department2,x) Result The expected result is like: Department <- c("Department_Store1","Departmentz_Store2","Department_Store3","Department_Store4","Department_Store5") Department2 <- c("Department2_IT1","Department2_IT2","Department2_IT3",

Insert Column Name into its Value using R

好久不见. 提交于 2021-02-08 08:52:05
问题 I need to insert Column Name, Department, into its value. i have code like here: Department <- c("Store1","Store2","Store3","Store4","Store5") Department2 <- c("IT1","IT2","IT3","IT4","IT5") x <- c(100,200,300,400,500) Result <- data.frame(Department,Department2,x) Result The expected result is like: Department <- c("Department_Store1","Departmentz_Store2","Department_Store3","Department_Store4","Department_Store5") Department2 <- c("Department2_IT1","Department2_IT2","Department2_IT3",

How to divide a given time series dataset into 4 hour window in R

房东的猫 提交于 2021-02-08 08:21:01
问题 I have a time series dataframe like this for a given day. Datetime <- c("2015-09-29 00:00:13", "2015-09-29 00:45:00", "2015-09-29 02:53:20", "2015-09-29 03:22:18", "2015-09-29 05:42:10", "2015-09-29 05:55:50", "2015-09-29 06:14:10", "2015-09-29 07:42:16", "2015-09-29 08:31:15", "2015-09-29 09:13:10", "2015-09-29 11:45:14", "2015-09-29 11:56:00", "2015-09-29 13:44:00", "2015-09-29 14:41:20", "2015-09-29 15:33:10", "2015-09-29 15:24:00", "2015-09-29 17:24:12", "2015-09-29 17:28:16", "2015-09-29

How to divide a given time series dataset into 4 hour window in R

巧了我就是萌 提交于 2021-02-08 08:20:10
问题 I have a time series dataframe like this for a given day. Datetime <- c("2015-09-29 00:00:13", "2015-09-29 00:45:00", "2015-09-29 02:53:20", "2015-09-29 03:22:18", "2015-09-29 05:42:10", "2015-09-29 05:55:50", "2015-09-29 06:14:10", "2015-09-29 07:42:16", "2015-09-29 08:31:15", "2015-09-29 09:13:10", "2015-09-29 11:45:14", "2015-09-29 11:56:00", "2015-09-29 13:44:00", "2015-09-29 14:41:20", "2015-09-29 15:33:10", "2015-09-29 15:24:00", "2015-09-29 17:24:12", "2015-09-29 17:28:16", "2015-09-29

Filtering with a set of values in r (dplyr)

风流意气都作罢 提交于 2021-02-08 08:16:25
问题 I have a question regarding filtering using the dplyr package in R . I have a current dataframe as follows: url season salary <fct> <fct> <dbl> 1 /players/a/abrinal01.html 2016-17 5725000 2 /players/a/ackeral01.html 2008-09 711517 3 /players/a/acyqu01.html 2012-13 788872 4 /players/a/acyqu01.html 2013-14 915243 5 /players/a/acyqu01.html 2014-15 981348 6 /players/a/acyqu01.html 2015-16 1914544 7 /players/a/acyqu01.html 2016-17 1709538 8 /players/a/adamsjo01.html 2014-15 1404600 9 /players/a

Outer operation by group in R

人走茶凉 提交于 2021-02-08 08:13:24
问题 My problem involves calculating differences in prices across products for each period. With the sample data below product = c('A','A','A','B','B','B','C','C','C') date = as.Date(c('2016-09-12','2016-09-19', '2016-09-26','2016-09-12','2016-09-19', '2016-09-26', '2016-09-12','2016-09-19', '2016-09-26')) price = as.numeric(c(17, 14.7, 15, 14.69, 14.64, 14.63, 13.15, 13.15, 13.15)) df <- data.frame(product, date, price) The challenge is in the grouping, without which a simple call to the outer

structuring binary data for sankey plot

橙三吉。 提交于 2021-02-08 07:50:41
问题 I am having trouble figuring out how to make a sankey plot for data where there are multiple opportunities of success (1) or failure (0). You can generate my sample with the following code: # example library(networkD3) library(tidyverse) library(tidyr) set.seed(900) n=1000 example.data<-data.frame("A" = rep(1,n), "B" = sample(c(0,1),n,replace = T), "C" = rep(NA,n), "D" = rep(NA,n), "E" = rep(NA,n), "F" = rep(NA,n), "G" = rep(NA,n)) for (i in 1:n){ example.data$C[i]<- ifelse(example.data$B[i]=

structuring binary data for sankey plot

霸气de小男生 提交于 2021-02-08 07:50:21
问题 I am having trouble figuring out how to make a sankey plot for data where there are multiple opportunities of success (1) or failure (0). You can generate my sample with the following code: # example library(networkD3) library(tidyverse) library(tidyr) set.seed(900) n=1000 example.data<-data.frame("A" = rep(1,n), "B" = sample(c(0,1),n,replace = T), "C" = rep(NA,n), "D" = rep(NA,n), "E" = rep(NA,n), "F" = rep(NA,n), "G" = rep(NA,n)) for (i in 1:n){ example.data$C[i]<- ifelse(example.data$B[i]=

How to correctly order segments by value, within an individual bar, on a bar chart in ggplot (even when changing from a factor)

北城以北 提交于 2021-02-08 07:39:38
问题 I am trying in vain to get the segments within each bar of the bar chart to order based on the value (largest value within a bar on the bottom, smallest on top). I've researched this and would think this should work, but something is not right and I can't find the issue. I tried this solution here, but no luck. Here is a reproducible example: library(dplyr) my_repro <- structure(list(Date = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "2020-04-01", class =