Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adply() does not work with mean() or median() function #296

Open
tht18 opened this issue Nov 28, 2019 · 0 comments
Open

adply() does not work with mean() or median() function #296

tht18 opened this issue Nov 28, 2019 · 0 comments

Comments

@tht18
Copy link

tht18 commented Nov 28, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant