简体   繁体   中英

How to fix “Error in `$<-.data.frame`(`*tmp*`, ”x“, value = 1L) : replacement has 1 row, data has 0” when using upsetR?

Below a simulated data which will be an input to upset() function

nobs <- 4000
pb <- round(runif(n=1, min=0.1, max=0.8),1)
August <- rbinom(n=nobs, size=1, prob=pb)
pb <- round(runif(n=1, min=0.1, max=0.8),1)
September <- rbinom(n=nobs, size=1, prob=pb)
pb <- round(runif(n=1, min=0.1, max=0.8),1)
October <- rbinom(n=nobs, size=1, prob=pb)
pb <- round(runif(n=1, min=0.1, max=0.8),1)
November <- rbinom(n=nobs, size=1, prob=pb)
pb <- round(runif(n=1, min=0.1, max=0.8),1)
December <- rbinom(n=nobs, size=1, prob=pb)

#generate random id
myFun <- function(n = nobs) {
  a <- do.call(paste0, replicate(5, sample(LETTERS, n, TRUE), FALSE))
  paste0(a, sprintf("%04d", sample(9999, n, TRUE)), sample(LETTERS, n, TRUE))
}

AumPre <- round(runif(n=nobs, min=100000, max=250000))
AumAft <- round(runif(n=nobs, min=100000, max=250000))
AumIncrease <- as.integer(AumAft > AumPre)
ncust <- myFun()
df <- data.frame(ncust
             , August
             , September
             , October
             , November
             , December
             , AumPre
             , AumAft
             , AumIncrease)
upset(df, boxplot.summary = c("AumAft"))

I keep getting the following error when calling upset().

Error in `$<-.data.frame`(`*tmp*`, "x", value = 1L) : 
  replacement has 1 row, data has 0

It seems others have encountered similar issues as reported here https://github.com/hms-dbmi/UpSetR/issues/93

Hope to get a workaround on this. I like the visualisation, but couldn't make it happen when using my own datasets.

Thanks

I think the package may look for the first and last binary columns and consider all columns in between to be part of the sets. When you rearrange your columns, the issue goes away.


library(tidyverse)

df <- df %>% 
  select(ncust, AumPre, AumAft, August, September, October, November, December, AumIncrease)

upset(df)
upset(df, boxplot.summary = c("AumAft"))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM