[R] replacement has 0 rows, data has 2809
Humberto Munoz Barona
hmunoz40 at hotmail.com
Sat Jun 18 01:53:01 CEST 2016
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
> countDf$effLength <- countDf$length - 170.71 + 1
Error in `$<-.data.frame`(`*tmp*`, "effLength", value = numeric(0)) :
replacement has 0 rows, data has 2809
> countDf$tpm <- with(countDf, countToTpm(count, effLength))
Error in countToTpm(count, effLength) : object 'count' not found
> countDf$fpkm <- with(countDf, countToFpkm(count, effLength))
Error in countToFpkm(count, effLength) : object 'count' not found
> with(countDf, all.equal(tpm, fpkmToTpm(fpkm)))
Error in all.equal(tpm, fpkmToTpm(fpkm)) : object 'tpm' not found
> countDf$effCounts <- with(countDf, countToEffCounts(count, length, effLength))
Error in countToEffCounts(count, length, effLength) :
object 'count' not found
>
Thanks for any help to fix this error
Humberto Munoz
More information about the R-help
mailing list