Skip to content

replacement has 0 rows, data has 2809

2 messages · Humberto Munoz Barona, Jim Lemon

#
I am running the following R-code 

countToTpm <- function(counts, effLen)
{
  rate <- log(counts) - log(effLen)
  denom <- log(sum(exp(rate)))
  exp(rate - denom + log(1e6))
}

countToFpkm <- function(counts, effLen)
{
  N <- sum(counts)
  exp( log(counts) + log(1e9) - log(effLen) - log(N) )
}

fpkmToTpm <- function(fpkm)
{
  exp(log(fpkm) - log(sum(fpkm)) + log(1e6))
}

countToEffCounts <- function(counts, len, effLen)
{
  counts * (len / effLen)
}
################################################################################
# An example
################################################################################
data1 <- read.delim("Dark Aerobic1.csv", check.names=FALSE, stringsAsFactors=FALSE)
cnts <- data1['ReadCount']
lens <- data1['Length']
countDf <- data.frame(count = cnts, length = lens)

 # assume a mean(FLD) = 170.71

countDf$effLength <- countDf$length - 170.71 + 1
countDf$tpm <- with(countDf, countToTpm(count, effLength))
countDf$fpkm <- with(countDf, countToFpkm(count, effLength))
with(countDf, all.equal(tpm, fpkmToTpm(fpkm)))
countDf$effCounts <- with(countDf, countToEffCounts(count, length, effLength))

 I am receiving the errors
Error in `$<-.data.frame`(`*tmp*`, "effLength", value = numeric(0)) : 
  replacement has 0 rows, data has 2809
Error in countToTpm(count, effLength) : object 'count' not found
Error in countToFpkm(count, effLength) : object 'count' not found
Error in all.equal(tpm, fpkmToTpm(fpkm)) : object 'tpm' not found
Error in countToEffCounts(count, length, effLength) : 
  object 'count' not found
Thanks for any help to fix this error

Humberto Munoz
#
Hi Humberto,
The "0 row" error usually arises from a calculation in which a
non-existent object is used. I see that you have created a vector with
the name "lens" and that may be where this is happening. Have a look
at:

length(lens)

or if it is not too long, just:

lens

If it is zero length, that is your problem. This might be due to
"data1" not having a column named "Length" or it may not contain
numeric values (i.e. a factor)..

Jim


On Sat, Jun 18, 2016 at 9:53 AM, Humberto Munoz Barona
<hmunoz40 at hotmail.com> wrote: