How can I rename the output rows / columns of ** ply functions from plyr?

I would like to specify the row / column names in functions **ply, ldplyfrom plyr package.

eg,

I have a list foothat I want to convert to data.frameand crop significant digits withsignif()

 foo <- list(var.a = runif(3), var.b = runif(3), var.c=runif(3))

Now I have

q <- ldply(foo, signif, 2)
colnames(dq)[1] <- c('id', 'q1', 'q2','q3')
rownames(dq) <- dq$id

Is there an easier way?

The two previous questions asked the question of how to use plyr to rename rows and cols using plyr, but I think my question is different. Can names be specified simultaneously with another function (or if I do it right)? Is this a useful feature request?

+5
source share
1 answer

-, , , ,

R> ldply(foo, function(l) c(a=signif(l[1], 2), b=signif(l[2], 2), 
+                           c=signif(l[3], 2)))
    .id    a    b    c
1 var.a 0.50 0.72 0.27
2 var.b 0.82 0.38 0.24
3 var.c 0.13 0.27 0.81
R> 

.

, , data.frame . *dply() . data.frame. .

+6

All Articles