sunpreet batra sunpreet batra - 1 year ago 62
R Question

Comparing data of single row with multiple rows

I have data of about 400 students and need to analyze these giving inferences to individual student about their performances in respective subjects compared to other students.

student data

Students are in rows and subjects are in columns.
I am new to data science if anybody please can help me with this, i would be grateful.

Answer Source

You could compare the individual students to the whole sample by subtracting the mean() of the columns from the values.

Lets assume your data.frame in R looks like your example above, and every column besides the first two are subjects.

new.data <- cbind(old.data[1:2], 
                  as.data.frame(lapply(old.data[3:ncol(old.data)], 
                                function(x) {x - mean(x, na.rm = TRUE)})))

This should give you a new data.frame with the difference between the person's individual score and the overall score of the subject across all your students.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download