r

gganimate: data present only in some frames

主宰稳场 提交于 2021-02-11 17:57:42
问题 I have a problem animating plots where data in some layers in present only in some of the frames. In the example below, I have a moving point that can be nicely animated along 9 frames. However, when I add another layer with a point present only in some of the frames, I get the following error: Error: time data must be the same class in all layers Example : require(data.table) require(ggplot2) require(gganimate) # 9 points along x=y; present at every time point dtP1 = data.table(x = 1:9, y =

gganimate: data present only in some frames

我的梦境 提交于 2021-02-11 17:57:20
问题 I have a problem animating plots where data in some layers in present only in some of the frames. In the example below, I have a moving point that can be nicely animated along 9 frames. However, when I add another layer with a point present only in some of the frames, I get the following error: Error: time data must be the same class in all layers Example : require(data.table) require(ggplot2) require(gganimate) # 9 points along x=y; present at every time point dtP1 = data.table(x = 1:9, y =

Perform multiple linear regression with variables based on shiny widget selection

拥有回忆 提交于 2021-02-11 17:57:14
问题 I would like to perform multiple linear regression in a shiny app but every time I would like to change dependent and independent variables based on 2 shiny widgets. Could this be achieved? library(shiny) library(shinydashboard) library(shinydashboardPlus) library(shinyWidgets) library(dplyr) shinyApp( ui = dashboardPagePlus( header = dashboardHeaderPlus(title = "Social Media Metrics", titleWidth = 320 ), sidebar = dashboardSidebar(width = 320, uiOutput("value"), uiOutput("value2") ), body =

Count consecutive days by group

人走茶凉 提交于 2021-02-11 17:51:09
问题 I am looking to add a field that counts the number of consecutive days within each group (captured by id field). I start with this: dt <- structure(list(id = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), date = c("1/01/2000", "2/01/2000", "2/01/2000", "5/01/2000", "6/01/2000", "7/01/2000", "8/01/2000", "13/01/2000", "14/01/2000", "18/01/2000", "19/01/2000", "21/01/2000", "25/01/2000", "26/01/2000", "30/01/2000", "31/01/2000")), .Names = c("id", "date"), row.names = c(NA,

T-test using two dfs in R

霸气de小男生 提交于 2021-02-11 17:43:02
问题 I am trying to run a t-test to determine if a column in one df is significantly different from a column in another df. I have two dfs, "block 1" and "block 2". I have tried this code: t.test(block1$Duration ~ block2$Duration, paired=FALSE, var.equal=TRUE) And I received this error message: Error in t.test.formula(block1$Duration ~ block2$Duration, paired = FALSE, : grouping factor must have exactly 2 levels Any insight into what I'm doing wrong is appreciated! 来源: https://stackoverflow.com

R apply multiple functions when large number of categories/types are present using case_when (R vectorization)

夙愿已清 提交于 2021-02-11 17:24:10
问题 Suppose I have a dataset of the following form: City=c(1,2,2,1) Business=c(2,1,1,2) ExpectedRevenue=c(35,20,15,19) zz=data.frame(City,Business,ExpectedRevenue) zz_new=do.call("rbind", replicate(zz, n=30, simplify = FALSE)) My actual dataset contains about 200K rows. Furthermore, it contains information for over 100 cities. Suppose, for each city (which I also call "Type"), I have the following functions which need to be applied: #Writing the custom functions for the categories here Type1

R, dbGetQuery() will not select records for all values passed in params

这一生的挚爱 提交于 2021-02-11 17:17:18
问题 I am trying to get dbGetQuery to retrieve all rows referenced in a char list (test_ID2) from a SybaseIQ table (test_in). The result is that only the first entry in test_ID2 is retrieved. the dbGetQuery() looks like this: test_con <- DBI::dbConnect(odbc::odbc(), driver = 'SybaseIQ', host = 'xxx.xx.xxx', port = 'xxxx', uid = 'xxxx', pwd = 'xxxx') test_out <- dbGetQuery(test_con,"SELECT * FROM test_in WHERE ID2 = ?", params = list(test_ID2)) test_in looks like this: > test_in ID1 DATE ID2 QTY

R, dbGetQuery() will not select records for all values passed in params

南楼画角 提交于 2021-02-11 17:17:14
问题 I am trying to get dbGetQuery to retrieve all rows referenced in a char list (test_ID2) from a SybaseIQ table (test_in). The result is that only the first entry in test_ID2 is retrieved. the dbGetQuery() looks like this: test_con <- DBI::dbConnect(odbc::odbc(), driver = 'SybaseIQ', host = 'xxx.xx.xxx', port = 'xxxx', uid = 'xxxx', pwd = 'xxxx') test_out <- dbGetQuery(test_con,"SELECT * FROM test_in WHERE ID2 = ?", params = list(test_ID2)) test_in looks like this: > test_in ID1 DATE ID2 QTY

R, dbGetQuery() will not select records for all values passed in params

久未见 提交于 2021-02-11 17:15:49
问题 I am trying to get dbGetQuery to retrieve all rows referenced in a char list (test_ID2) from a SybaseIQ table (test_in). The result is that only the first entry in test_ID2 is retrieved. the dbGetQuery() looks like this: test_con <- DBI::dbConnect(odbc::odbc(), driver = 'SybaseIQ', host = 'xxx.xx.xxx', port = 'xxxx', uid = 'xxxx', pwd = 'xxxx') test_out <- dbGetQuery(test_con,"SELECT * FROM test_in WHERE ID2 = ?", params = list(test_ID2)) test_in looks like this: > test_in ID1 DATE ID2 QTY

Replicating identical tabs and layouts over and over

泄露秘密 提交于 2021-02-11 17:06:04
问题 I am creating an app in which several inputs are displayed in a tab. I would like the user to be able to generate an identical tab (with the same layout) by clicking on a tab dedicated to it (it will be clearer with the example). Therefore, one user could potentially create an infinite number of identical tabs. However, the name given to the inputs should change slightly (e.g. select1 , select2 , etc.) so that these newly created inputs can be used in a reactive way. Moreover, the tabs should