2

I'm new to R and want to calculate the RMSE of two groups of data held within the same .csv file.

.csv contains something like this:

Group  X      Y
A      2      2
A      3      2
B      2      7
B      6      5

My poor attempt at retrieving the RMSE for just those in Group A:

myData=read.csv("foo.csv")
attach(myData)

library(Metrics)
if (row.names(A)) {
  rmse(x,y)
}

Do I need to append A and B to seperate dataframes before I can calculate RMSE, or is there a better way to achieve this?

Thanks in advance!

Lex
  • 27
  • 4

1 Answers1

2

dplyr could be useful for you because you can group by different groups within a column. Something like:

library(dplyr)
myData %>%
   group_by(Group) %>%
   summarize(RMSE = rmse(x, y))
Bear
  • 662
  • 1
  • 5
  • 20