r

R shiny dynamic UI in insertUI

两盒软妹~` 提交于 2021-02-19 02:24:05
问题 I have a Shiny application where I would like to add a UI element using an action button and then have that inserted ui be dynamic. Here is my current ui file: library(shiny) shinyUI(fluidPage( div(id="placeholder"), actionButton("addLine", "Add Line") )) and server file: library(shiny) shinyServer(function(input, output) { observeEvent(input$addLine, { num <- input$addLine id <- paste0("ind", num) insertUI( selector="#placeholder", where="beforeBegin", ui={ fluidRow(column(3, selectInput

Combine select and mutate

倖福魔咒の 提交于 2021-02-19 02:19:42
问题 Quite often, I find myself manually combining select() and mutate() functions within dplyr. This is usually because I'm tidying up a dataframe, want to create new columns based on the old columns, and only want keep the new columns. For example, if I had data about heights and widths but only wanted to use them to calculate and keep the area then I would use: library(dplyr) df <- data.frame(height = 1:3, width = 10:12) df %>% mutate(area = height * width) %>% select(area) When there are a lot

Combine select and mutate

倾然丶 夕夏残阳落幕 提交于 2021-02-19 02:19:38
问题 Quite often, I find myself manually combining select() and mutate() functions within dplyr. This is usually because I'm tidying up a dataframe, want to create new columns based on the old columns, and only want keep the new columns. For example, if I had data about heights and widths but only wanted to use them to calculate and keep the area then I would use: library(dplyr) df <- data.frame(height = 1:3, width = 10:12) df %>% mutate(area = height * width) %>% select(area) When there are a lot

Combine select and mutate

给你一囗甜甜゛ 提交于 2021-02-19 02:18:41
问题 Quite often, I find myself manually combining select() and mutate() functions within dplyr. This is usually because I'm tidying up a dataframe, want to create new columns based on the old columns, and only want keep the new columns. For example, if I had data about heights and widths but only wanted to use them to calculate and keep the area then I would use: library(dplyr) df <- data.frame(height = 1:3, width = 10:12) df %>% mutate(area = height * width) %>% select(area) When there are a lot

Combine select and mutate

谁说胖子不能爱 提交于 2021-02-19 02:18:16
问题 Quite often, I find myself manually combining select() and mutate() functions within dplyr. This is usually because I'm tidying up a dataframe, want to create new columns based on the old columns, and only want keep the new columns. For example, if I had data about heights and widths but only wanted to use them to calculate and keep the area then I would use: library(dplyr) df <- data.frame(height = 1:3, width = 10:12) df %>% mutate(area = height * width) %>% select(area) When there are a lot

How to convert an ambiguous datetime column in data.table without using strptime?

ぃ、小莉子 提交于 2021-02-19 02:18:12
问题 My data.table has a column with an "ambiguous" datetime format: "12/1/2016 15:30". How can I convert this datetime to a format R recognizes in a data.table without using strptime() and getting the warning message for initially converting to POSIXlt. The process works but the warning makes me think there is another way. My data table: my_dates <- c("12/1/2016 15:30", "12/1/2016 15:31", "12/1/2016 15:32") this <- c("a", "b", "c") that <- c(1, 2, 3) my_table <- data.table(my_dates, this, that)

Why does dplyr error in this nested if_else, when logical condition means output should not be evaluated?

老子叫甜甜 提交于 2021-02-19 02:18:05
问题 I have a nested if_else statement inside mutate . In my example data frame: tmp_df2 <- data.frame(a = c(1,1,2), b = c(T,F,T), c = c(1,2,3)) a b c 1 1 TRUE 1 2 1 FALSE 2 3 2 TRUE 3 I wish to group by a and then perform operations based on whether a group has one or two rows. I would have thought this nested if_else would suffice: tmp_df2 %>% group_by(a) %>% mutate(tmp_check = n() == 1) %>% mutate(d = if_else(tmp_check, # check for number of entries in group 0, if_else(b, sum(c)/c[b == T], sum

Why does dplyr error in this nested if_else, when logical condition means output should not be evaluated?

杀马特。学长 韩版系。学妹 提交于 2021-02-19 02:17:59
问题 I have a nested if_else statement inside mutate . In my example data frame: tmp_df2 <- data.frame(a = c(1,1,2), b = c(T,F,T), c = c(1,2,3)) a b c 1 1 TRUE 1 2 1 FALSE 2 3 2 TRUE 3 I wish to group by a and then perform operations based on whether a group has one or two rows. I would have thought this nested if_else would suffice: tmp_df2 %>% group_by(a) %>% mutate(tmp_check = n() == 1) %>% mutate(d = if_else(tmp_check, # check for number of entries in group 0, if_else(b, sum(c)/c[b == T], sum

Why does dplyr error in this nested if_else, when logical condition means output should not be evaluated?

家住魔仙堡 提交于 2021-02-19 02:17:03
问题 I have a nested if_else statement inside mutate . In my example data frame: tmp_df2 <- data.frame(a = c(1,1,2), b = c(T,F,T), c = c(1,2,3)) a b c 1 1 TRUE 1 2 1 FALSE 2 3 2 TRUE 3 I wish to group by a and then perform operations based on whether a group has one or two rows. I would have thought this nested if_else would suffice: tmp_df2 %>% group_by(a) %>% mutate(tmp_check = n() == 1) %>% mutate(d = if_else(tmp_check, # check for number of entries in group 0, if_else(b, sum(c)/c[b == T], sum

Why does dplyr error in this nested if_else, when logical condition means output should not be evaluated?

拜拜、爱过 提交于 2021-02-19 02:15:20
问题 I have a nested if_else statement inside mutate . In my example data frame: tmp_df2 <- data.frame(a = c(1,1,2), b = c(T,F,T), c = c(1,2,3)) a b c 1 1 TRUE 1 2 1 FALSE 2 3 2 TRUE 3 I wish to group by a and then perform operations based on whether a group has one or two rows. I would have thought this nested if_else would suffice: tmp_df2 %>% group_by(a) %>% mutate(tmp_check = n() == 1) %>% mutate(d = if_else(tmp_check, # check for number of entries in group 0, if_else(b, sum(c)/c[b == T], sum