Here is my dataframe df:
x y1 1 1
2 1 2
3 2 3
And I get the result:
2
3
with the code:
tapply(df$y, df$x, sum)
But I expect to get
3
3
Is there something wrong with my code?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’re getting the correct answer, just reading it wrong.
look at the whole output:
Your groups are 1 and 2 and the values are 3 and 3. Is horizontal. You can see this if you try
tapplyin the other direction