Custom function not recognized by ddply {plyr}, it tells me that my function is not a function

I have a matrix called (b2) that contains 3565 rows and 125 columns with only dichotomous values ​​(0 and 1)

I developed a function for comparing strings iand row i+1and saved the number of differences in a new vector.

loopPhudcf <- function(x){
  ## create a vector to store the results of your for loop
  output <- as.vector(rep(0, length(x[,1])))
  for (i in 1:(nrow(x))-1)  {
    output[i]<-as.vector(table(x[i,]==x[i+1,]))[1]
  }
  a<-nrow(x)
  b<-nrow(x)-1
  output<-t(as.matrix(output[c(a,1:b)]))
  output[output==ncol(x)]<-0
  return(output)
}

phudcfily123<-loopPhudcf(b2)

The function works fine, but I also have an identifier variable, which I added to my original matrix using: b2<-transform(b2,id=a$id)and then, as a result, 3565 by 126 is the last id variable

I wanted to apply my function using ddply {plyr}, but for this I only need to multiply my original matrix without the variable ID ( as.matrix(b2[,1:(ncol(b2)-1)])), but it continues to say that my function is not a function: (

x <- ddply(.data = b2, .var = c("id"), .fun = loopPhudcf(as.matrix(b2[,1:(ncol(b2)-1)])))

Error in llply(.data = .data, .fun = .fun, ..., .progress = .progress,  : 
  .fun is not a function.

- ?

0
2

, reshape, , , :

x<-sparseby(as.matrix(b2[,1:125]),list(group = b2[,126]), function(subset) loopPhudcf(as.matrix(b2[,1:125])))

- , , , ,

dim(x)
[1]  155 3566

, , , . 3565 :

x1<-x[1,2:ncol(x)]

2, , id b2. !

0

.fun ; , . .

x <- ddply(.data = b2, .var = c("id"), .fun = function(b2s) {loopPhudcf(as.matrix(b2[,1:(ncol(b2)-1)]))}

b2 b2s; , , b2 b2.

(, b2.)

+3

All Articles