0

Sample data

I have a data set that deals with hr data. Each row is an employee id and the columns represent scores on questions they were asked.

I want to total the scores on all Common and Tech questions(theres 39 Common Questions and 39 Tech Questions) for each employee. Whenever I try to do this the totals column shows up with all zeros. Not sure where I went wrong.

Dat is what my data is called, code runs fine with no errors but the totals column just shows up with zero as every value. Thank you in advance! also newbie so if theres any glaring mistakes I apologize, would appreciate some links that will help me get better too! Here is the code that I wrote to try to do it.

techs<-grep("^T",rownames(dat),value=TRUE)
commons<-grep("^C",rownames(dat),value=TRUE)
type_q=rep("Common",dim(dat)[1])
type_q[techs]="Technical"
dat$totals<-rowSums(dat[,techs])+rowSums(dat[,commons])
Phil
  • 7,287
  • 3
  • 36
  • 66
  • Hi Kathryn, if you could provide a minimum subset of your data (for example using `dput`) so that your code can be easily cut into other peoples' R consoles it will help us get you a solution. It is also helpful to show exactly what the output data frame would look like with correct solution for you. Thanks :) – mysteRious May 08 '20 at 22:50
  • did you check the class of the variables? – Mohanasundaram May 09 '20 at 12:35

0 Answers0