-2

I'm a freshman learning R, and I am stuck on some homework.

Data frame:

student HW1 HW2 EXAM1 HW3 HW4
A       100 95  80    96  100
B       98  100 89    100 100
C       90  95  90    88  90

My question is how do I create a new column that contains the homework average? This new column should be the last column and aligned to each student.

The apply function, grep function and rowMeans may be used in this assignment.

What should I try next?

4

1 に答える 1

3
df1$hwavg <- rowMeans(df1[,grep("^H",names(df1))])
于 2013-06-12T03:44:42.653 に答える