[R] replacement has 0 rows, data has 2809

Jim Lemon drjimlemon at gmail.com
Sat Jun 18 09:19:31 CEST 2016


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:
> 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
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list