r - Preserve column names when ddply returns empty dataframe -
i using ddply homecoming dataframe, if returned dataframe each element of initial dataframe contains no rows final output empty dataframe 1 column, initial variable. want homecoming empty dataframe columns have returned if did have data.
for illustration if have next
y <- data.frame(a = 1:5, b = 6:10) res1 <- ddply(y, .(a), function(x) subset(x, b == 6)) res2 <- ddply(y, .(a), function(x) subset(x, b == 5))
res1 returns dataframe column & b, whereas res2 returns column - homecoming empty dataframe columns , b.
running next works
res3 <- dlply(y, .(a), function(x) subset(x, b == 5)) res3 <- do.call('rbind', res3)
but there way in 1 go using ddply?
thanks in advance
r plyr
No comments:
Post a Comment