-1

Sorry I am new to R, and the problem is quite hard for me,
Here is the matrix:

        V1              predictions
1   Jeffery Howes   0.0909596345057677
2   Sherilee Waring 0.00434589236424605
3   Rachel Maitland 0.0909596345057677
4   Jan Maitland    0.0909596345057677
5   Jan Maitland    0.0909596345057677
6   Jan Maitland    0.0909596345057677
7   Jan Maitland    0.0909596345057677
8   Sandra McEwen   0.0909596345057677
....  

How can I remove the duplicates in the columns (that's okay for me, could use unique, but the following problem is quite hard for me).

For example, there are many duplicated name Jan Maitland, duplicates should be removed, but the predications values should be calculated (the final result left should be the average value of those duplicate names)

Could someone help me on that? thanks a lot!!

1

1 Answer 1

1

you can use the dplyr library :

result%.%group_by(V1)%.%summarise(predictions = mean(predictions))
# the 2nd syntax
summarise(group_by(result, V1), predictions=mean(predictions))

hth

Sign up to request clarification or add additional context in comments.

6 Comments

thanks! what's the meaning of tab? forget to mention that the matrix name is result, so it should be result%.%group_by(V1)%.%summarise(predictions = mean(predictions))??
Hi droppy, not quite understand the %.%
yes it should be result instead of tab and result must be a data.frame and a not a matrix; I'll edited the post
thanks! btw, how should I convert matrix to data.frame
as.data.frame(result)?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.