apply() in R with user-defined function

getpos <- function(x, vorl="v"){ 
     vot <- x[grep( "v", names(x) )] ;  lab <- x[grep( "l", names(x) )];
     if (vorl=="v") {vot[vot>0]} else {lab[vot>0]};
 }

> apply(dat, MARGIN=1, FUN=function(x2) getpos(x2, vorl="l") )
for(i in 1:length(mytxtfiles)){
lapply(mytxtfiles[i], FUN=function(txt_name) dlm_OpenNLR(txt_name))
}

你可能感兴趣的:(apply() in R with user-defined function)