Hello,
I'm trying to calculate the total amount and average amount of volume left in some tubes in a large data set. I thought this would be a simple task of using rowSums and then a rowMeans function and creating a few more columns, however I keep getting the same errors and I can't seem to work around it.
My code is essentially:
practice<-data.frame("parent"=c("001","001","001","001","002","002","002","002",
"003","003","003","003","004","004","004","004"),"tube"=c("tube1",
"tube2","tube3","tube4","tube1","tube2","tube3","tube4",
"tube1","tube2","tube3","tube4","tube1","tube2","tube3","tube4"),
"microlitres"=c(100,120,60,100,NA,200,100,120,
60,100,120,40,100,120,400,NA))
pivot_wider(practice,names_from = tube,values_from = microlitres)->practice
practice$sum<-rowSums(practice,na.rm=TRUE)
I get an error saying "x must be numeric", but when I try
practise$sum<-rowSums(as.numeric(practise),na.rm=TRUE)
I then get an error saying "list object cannot be coerced into double". I feel like I've tried everything, unlisting things, making it a matrix, using the mutate function... I know whatever it is will probably be a simple solution, but any help or advice would be greatly appreciated.