Tag: list

  • Getting names while applying sapply or l …

    Getting names while applying sapply or lapply in R.
    sapply or lapply extract the element without the row name.
    So this code does not work.

    par(mfrow = c(4,4))
    sapply(names(score.avg)
           , function(x) {
               plot(x
                    , type = 'l'
                  );
               title(main=names(x))      
               })
    

    In order to use the row names while applying sapply or apply,
    pass the names of the list to a function and call the values using the names.

    par(mfrow = c(4,4))
    sapply( modne portale randkowe names(score.avg)
           , function(x) {
               xlength <- length(score.avg[[x]]);         
               plot(-499:(xlength-499-1),  sant jordi busco mujeres solteras score.avg[[x]]
                    , type = 'l'
                    , xlab='Distance from TSS', ylab='score'
                 #   , xlim=c(-100,100)
                  );
               title(main=x, cex.main=0.85);
               })