0

I currently have a table in R with 4 columns and I want to average the last two columns (titled W10CP1 and W10CP2) into a 5th column of that table.

I tried to use rowMeans but I got an error.

Sorry for the basic question!

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
user9069732
  • 1
  • 1
  • 4
  • 3
    How did you use it and what is the error? Based on the info, it should be `rowMeans(tbl[,c("W10CP1", "W10CP2)], na.rm = TRUE)` – akrun Jun 25 '18 at 14:43
  • 1
    what is the result of `sapply(yourDATA,class)` – Andre Elrico Jun 25 '18 at 14:44
  • 3
    When you post a question on SO that references an error, it does us no good to say "*I got an error*". Which one? There are countless. Please quickly read about [reproducible questions](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example), as well as SO's help-pages on [minimal, verifiable examples](https://stackoverflow.com/help/mcve) and [how to ask good questions](https://stackoverflow.com/help/how-to-ask). You'll get more relevant comments/answers quickly if you follow their advice. – r2evans Jun 25 '18 at 14:46

1 Answers1

0

You can try use the tydeverse package here an example:

library(tidyverse)
data<-data%>% mutate(mean= (data[,-1] +data[,-2]/2))