+5 votes
2 views
in R Programming by (1.5k points)

I have a data  which consists of two columns "Students" & "points"

x<-data.frame(Students=c("Student1","Student2","Student3","Student2","Student3","Student1"),points=c(5,10,15,2,6,4))

Students points

1 Student1    5

2 Student2     10

3 Student3     15

4 Student2     2

5 Student3     6

6 Student1     4

I want to sort the data and find the  sum of the points in this way:

Students  x

1 Student1 9

2 Student2 12

3 Student3 21

1 Answer

+11 votes
by (10.6k points)

There are two methods by which you can add the variables and sort the data:

  • By using aggregate() function:

            aggregate(x$points, by=list(Students=x$Student), FUN=sum)

  • By using tapply() function:

           tapply(x$points, x$Students, FUN=sum)

Related questions

+1 vote
1 answer
asked Jul 31, 2019 in R Programming by Aarav (11.5k points)
+1 vote
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...