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

I would like to state the row/col output names in a **ply function, ldply, from the plyr package.

for example,

I have a list, foo, that I want to convert to a data.frame and truncate significant digits with signif()

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

What I have now is

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

Is there an easier way?

Two previous questions have asked how to use plyr to rename rows and cols using plyr, but I think my question is different. Can the names be stated at the same time as another function (or if I am doing this correctly)? Is this a worthwhile feature request?


You have to give names somewhere, either on the function being called inside as eg in

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

or has you did after the call.

Another option I frequently use is to explicitly create one-row data.frame in the anonymous worker function. *dply() et al then simply collated these into a single data.frame. That works well enough for my tastes.

Need Your Help

Design time data in Windows Store app

windows-8 microsoft-metro expression-blend

In WP7 I am used to generating sample data (XML) from my ViewModels in Blend and seeing them in Visual Studio.

How to implement small text list search functionality using CSS attribute selectors

javascript css

My requirement was to display contact list and in phonegap application. As JS execution is slow in Phonegap application is there any alternative with less JS overhead?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.