0
domainA <-read.csv("/Users/keke/Desktop/Data.and.Domains/Domains FormA.csv",header=TRUE, sep=",")
domainB <-read.csv("/Users/keke/Desktop/Data.and.Domains/Domains FormB.csv",header=TRUE, sep=",")
formA <-read.csv("/Users/keke/Desktop/Data.and.Domains/FormA.csv",header=FALSE, sep=",")
formB <-read.csv("/Users/keke/Desktop/Data.and.Domains/FormB.csv",header=FALSE, sep=",")

formA <- t(formA)
formB <- t(formB)
formA <- as.data.frame(formA)
formB <- as.data.frame(formB)
formA <- formA[-1,]
formB <- formB[-1,]


students.a <- vector("character")
for(i in 1:50) {
  students.a[i] <-2*i-1
}
students.b <- vector("character")
for(i in 1:50){
  if(i==32) next
students.b[i] <- 2*i
}
students.b <- students.b[(!is.na(students.b))]
students.a <- c("AKey", students.a)
students.b <- c("BKey", students.b)
colnames(formA) <- students.a
colnames(formB) <- students.b

TestA<- cbind(formA,domainA)
TestB<- cbind(formB,domainB)
ID <- c(students.a[2:51], students.b[2:50])
EXAM <- c(rep("A", 50), rep("B", 49))
stID <-c(students.A[2:51], students.B[2:50])
Exam <- c(rep("A",50),rep("B",49))

DetA<- formA[,2:51]==formA$Akey
  hitormissA <- formA[,2:51]==formA$AKey
  hitormissA <- apply(hitormissA, 2, as.numeric)
  scoreA <- apply(hitormissA, 2, sum)
  percentageA <- apply(hitormissA, 2, mean)
  percentageA <- percentageA*100

The code doesn't run from hitormiss A. The error says

Incompatible methods ("Ops.data.frame", "Ops.factor") for "=="Error in formA[, 2:51] == formA$AKey : 
  comparison of these types is not implemented
halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    Please make a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Conor Neilson Mar 28 '20 at 22:05

1 Answers1

0

From what I am understanding, you are trying to check via the logical operator " == " if

formA[,2:51] "is exactly equal to" formA$AKey

but class(formA[,2:51]) is a data.frame, while class(formA$AKey) is a factor!

Hence they cannot ever be equal in R, and therefore you get your error-message.

Check it out with:

class(formA[,2:51]) == class(formA$AKey)

I suggest you try to bring formA[,2:51] and formA$AKey to the same class and only then use a logical operator.

halfer
  • 19,824
  • 17
  • 99
  • 186
user12256545
  • 2,755
  • 4
  • 14
  • 28