r

Delete DataTable rows in Shiny app using Javascript

血红的双手。 提交于 2021-02-11 12:47:32
问题 I'm trying to remove rows from a Datatable in a Shiny app using Javascript. In the table I have a column with a "delete" button for each row. This would be more or less what I'm trying to do, but I can't get it to work. In my server.R: initComplete <- DT::JS( "function () {", " var table = this.api();", " $('#delete_button').on('click', function() {", " table.row($(this).parents('tr')).remove().draw();", " });", "}" ) shinyInput <- function(FUN, len, id, ...) { inputs <- character(len) for (i

Delete DataTable rows in Shiny app using Javascript

一笑奈何 提交于 2021-02-11 12:47:31
问题 I'm trying to remove rows from a Datatable in a Shiny app using Javascript. In the table I have a column with a "delete" button for each row. This would be more or less what I'm trying to do, but I can't get it to work. In my server.R: initComplete <- DT::JS( "function () {", " var table = this.api();", " $('#delete_button').on('click', function() {", " table.row($(this).parents('tr')).remove().draw();", " });", "}" ) shinyInput <- function(FUN, len, id, ...) { inputs <- character(len) for (i

Replace the same values in the consecutive rows and stop replacing once the value has changed in R

╄→гoц情女王★ 提交于 2021-02-11 12:47:06
问题 I want to find a way to replace consecutive same values into 0 at the beginning of each trial, but once the value has changed it should stop replacing and keep the value. It should occur every trials per subject. For example, first subject has multiple trials (1, 2, etc). At the beginning of each trial, there may be some consecutive rows with the same value (e.g., 1, 1, 1). For these values, I would like to replace them to 0. However, once the value has changed from 1 to 0, I want to keep the

How to create a stacked bar chart with 2 numeric variables in R using ggplot, grouped by 1 factor variable?

浪尽此生 提交于 2021-02-11 12:47:04
问题 I'm fairly new to R and this is my first question on here so apologies if I write it in a confusing way! Basically I have a dataframe with 4 columns, month and site which are factors, and organic % and inorganic % which are numeric: df<-data.frame(month = c("Mar", "Apr", "May", "Jun", "Jul", "Mar", "Apr", "May", "Jun", "Jul"), site = c("Borth", "Borth", "Borth", "Borth", "Borth", "Clarach", "Clarach", "Clarach", "Clarach", "Clarach"), organic = c(10,20,30,40,50), inorganic = c(90,80,70,60,50)

How to create a stacked bar chart with 2 numeric variables in R using ggplot, grouped by 1 factor variable?

烈酒焚心 提交于 2021-02-11 12:46:54
问题 I'm fairly new to R and this is my first question on here so apologies if I write it in a confusing way! Basically I have a dataframe with 4 columns, month and site which are factors, and organic % and inorganic % which are numeric: df<-data.frame(month = c("Mar", "Apr", "May", "Jun", "Jul", "Mar", "Apr", "May", "Jun", "Jul"), site = c("Borth", "Borth", "Borth", "Borth", "Borth", "Clarach", "Clarach", "Clarach", "Clarach", "Clarach"), organic = c(10,20,30,40,50), inorganic = c(90,80,70,60,50)

scraping with R using rvest and purrr, multiple pages

空扰寡人 提交于 2021-02-11 12:44:53
问题 I am trying to scrape a database containing information about previously sold houses in an area of Denmark. I want to retrieve information from not only page 1, but also 2, 3, 4 etc. I am new to R but from an tutorial i ended up with this. library(purrr) library(rvest) urlbase <- "https://www.boliga.dk/solgt/alle_boliger-4000ipostnr=4000&so=1&p=%d" map_df(1:5,function(i){ cat(".") page <- read_html(sprintf(urlbase,i)) data.frame(Address = html_text(html_nodes(page,".d-md-table-cell a")))

How to write a double for loop in r with choosing maximal element in one loop?

血红的双手。 提交于 2021-02-11 12:44:47
问题 I want to sample theta[j] as first for j=1,2,...,71, then draw replicated( like 1000 times) yrep[k] form Bin(n[j], theta[j]), n[j] is known. Then for each theta[j], I have 1000 yrep. If I want to choose the maximal element among this 1000 yrep. Finally, I will have 71 maximal elements. My for loop in R is as follows: theta<-NULL yrep<-NULL test<-NULL k=1 for(i in 1:1000){ for(j in 1:71){ theta[j] <- rbeta(1,samp_A+y[j], samp_B+n[j]-y[j]) yrep[k]<-rbinom(1, n[j], theta[j]) k=k+1 } t<-c(test,

Why won't pipe operator let me combine successive mutations?

心已入冬 提交于 2021-02-11 12:44:47
问题 I want to mutate columns from this... ...into... When I did the following... villastats<-villastats%>% mutate(HG = ifelse(HomeTeam == "Aston Villa", villastats$FTHG, ifelse(HomeTeam != "Aston Villa", 0, 0))) villastats<-villastats%>% mutate(AG = ifelse(AwayTeam == "Aston Villa", villastats$FTAG, ifelse(AwayTeam != "Aston Villa", 0, 0))) villastats<-villastats%>% mutate(THG=cumsum(villastats$HG)) villastats<-villastats%>% mutate(TAG=cumsum(villastats$AG)) villastats<-villastats%>% mutate(Tot

Error in R gbm function when cv.folds > 0

自作多情 提交于 2021-02-11 12:44:23
问题 I am using gbm to predict binary response. When I set cv.folds=0, everything works well. However when cv.folds > 1, I got error: Error in object$var.levels[[i]] : subscript out of bounds when the first irritation of crossvalidation finished. Someone said this could because some factor variables have missing levels in training or testing data, but I tried only use numeric variables and still get this error. > gbm.fit <- gbm(model.formula, + data=dataall_train, + distribution = "adaboost", + n

Rendering multiple parametrized Rmarkdown files by render_function() fails

痴心易碎 提交于 2021-02-11 12:41:44
问题 I wrote a parametrized report that will create individual reporting for ~120 centers in two different languages. The reports are created by the knit-button so far (which works perfectly fine). Inspired by @djnavarro's tweet (https://twitter.com/djnavarro/status/1101623527872970754) I tried writing a function to render multiple parametrized reports in one command, however, the function fails with Error as shown in the minimal reprex below: The .Rmd-file called summary_cyl.Rmd --- output: pdf