-
Notifications
You must be signed in to change notification settings - Fork 113
Description
adply() does not seem to work consistently. It does not work with some functions (i.e., mean(), median()) but does work with other functions (sum(), sd()) when applying to the same df of numeric values.
df = tibble(x = 1:10, y = 1:10)
plyr::adply(df, 1, mean)
x y V1
1 1 1 NA
2 2 2 NA
3 3 3 NA
4 4 4 NA
5 5 5 NA
6 6 6 NA
7 7 7 NA
8 8 8 NA
9 9 9 NA
10 10 10 NA
Warning messages:
1: In mean.default(piece, ...) :
argument is not numeric or logical: returning NA
2: In mean.default(piece, ...) :
argument is not numeric or logical: returning NA
3: In mean.default(piece, ...) :
argument is not numeric or logical: returning NA
4: In mean.default(piece, ...) :
argument is not numeric or logical: returning NA
5: In mean.default(piece, ...) :
argument is not numeric or logical: returning NA
6: In mean.default(piece, ...) :
argument is not numeric or logical: returning NA
7: In mean.default(piece, ...) :
argument is not numeric or logical: returning NA
8: In mean.default(piece, ...) :
argument is not numeric or logical: returning NA
9: In mean.default(piece, ...) :
argument is not numeric or logical: returning NA
10: In mean.default(piece, ...) :
argument is not numeric or logical: returning NA
plyr::adply(df, 1, median)
Error in median.default(piece, ...) : need numeric data
But works with sum():
plyr::adply(df, 1, sum)
x y V1
1 1 1 2
2 2 2 4
3 3 3 6
4 4 4 8
5 5 5 10
6 6 6 12
7 7 7 14
8 8 8 16
9 9 9 18
10 10 10 20
or sd():
plyr::adply(df, 1, sd)
x y V1
1 1 1 0
2 2 2 0
3 3 3 0
4 4 4 0
5 5 5 0
6 6 6 0
7 7 7 0
8 8 8 0
9 9 9 0
10 10 10 0