You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey! First, thanks very much for providing pbapply, it's really helpful!
I noticed a small issue when applying a function that returns a named vector to a data.frame. If the length of the returned vector is the same as the number of columns of the data.frame, then the rownames of the results from pbapply are not taken from the returned vector, but from the colnames of the data.frame. The standard apply function still takes the names from the returned vector.
Here is a minimal example:
library(pbapply)
## function that returns a named vector of length 3:
f <- function(x) {
return(c(mean = mean(x), median = median(x), sd = sd(x)))
}
### data.frame with 3 columns (= length of returned named vector)
D <- data.frame(matrix(runif(30), ncol = 3))
rownames(apply(D, 1, f))
# [1] "mean" "median" "sd"
rownames(pbapply(D, 1, f))
# [1] "X1" "X2" "X3"
### here the rownames are taken form the data.frame instead from the returned vector
### data.frame with 4 columns
D2 <- data.frame(matrix(runif(40), ncol = 4))
rownames(apply(D2, 1, f))
# [1] "mean" "median" "sd"
rownames(pbapply(D2, 1, f))
# [1] "mean" "median" "sd"
### here the rownames are the same as for apply
The text was updated successfully, but these errors were encountered:
Hey! First, thanks very much for providing pbapply, it's really helpful!
I noticed a small issue when applying a function that returns a named vector to a data.frame. If the length of the returned vector is the same as the number of columns of the data.frame, then the rownames of the results from pbapply are not taken from the returned vector, but from the colnames of the data.frame. The standard apply function still takes the names from the returned vector.
Here is a minimal example:
The text was updated successfully, but these errors were encountered: