[R] error: arguments imply differing number

jd6688 jdsignature at gmail.com
Wed Jul 28 15:59:52 CEST 2010


mydata <- read.table(textConnection("

 Id cat1 location item_values p-values sequence
a111 1 3002737     100             0.01       1
a112 1 3017821     102             0.05       2
a113 2 3027730     103             0.02       3
a114 2 3036220     104             0.04       4
a115 1 3053984     105             0.03       5
a118 1 3090500     106             0.02       8
a119 1 3103304     107             0.03       9
a120 2 3090500     106             0.02       10
a121 2 3103304     107             0.03       11

"), header = TRUE)

closeAllConnections()



first <- function(x)c(TRUE, diff(x)!=1)




last <- function(x)c(diff(x)!=1, TRUE)



mydata$start <- first(mydata$sequence)
mydata$end <- last(mydata$sequence)

mydata$runNumber <- cumsum(first(mydata$sequence))

#load library
library(plyr)


ddply(mydata[, -1], .(runNumber,cat1), function(x) {max(x$item_values)})



my.summary <- function(x) {
 start.loc <- x$location[which(x$start == TRUE)]
 end.loc <- x$location[which(x$end == TRUE)]
 peak <- max(x$item_values)
 output <- data.frame(
                      start_of_the_location = start.loc,
                      end_of_the_location = end.loc,
                      peak_value = peak)
 return(output)
}


ddply(mydata[, -1], .(runNumber,cat1), my.summary)

why ddply returned the following error

 Error in data.frame(start_of_the_location = start.loc, end_of_the_location
= end.loc,  : 
  arguments imply differing number of rows: 0, 1
> mydata[,-1]
  cat1 location item_values p.values sequence start   end runNumber
1    1  3002737         100     0.01        1  TRUE FALSE         1
2    1  3017821         102     0.05        2 FALSE FALSE         1
3    2  3027730         103     0.02        3 FALSE FALSE         1
4    2  3036220         104     0.04        4 FALSE FALSE         1
5    1  3053984         105     0.03        5 FALSE  TRUE         1
6    1  3090500         106     0.02        8  TRUE FALSE         2
7    1  3103304         107     0.03        9 FALSE FALSE         2
8    2  3090500         106     0.02       10 FALSE FALSE         2
9    2  3103304         107     0.03       11 FALSE  TRUE         2
> 

-- 
View this message in context: http://r.789695.n4.nabble.com/error-arguments-imply-differing-number-tp2305014p2305014.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list