Skip to content

check and verify

1 message · arun

#
HI,
Try this:
test<-read.table(text="
?A B C D E F
?a b c d 40 30
?a f a b 20 10
?x m y m 50 30
",sep="",header=TRUE,stringsAsFactors=FALSE)
#Here, stringsAsFactors=FALSE is the key here.? If you did not add that (or =TRUE) , by default, A-D columns will be factors and you will get the error message as described.

within(test,{new_column_2<-(B==D)*F;new_column_1<-(A==C)*E}) 
# A B C D? E? F new_column_1 new_column_2
#1 a b c d 40 30??????????? 0??????????? 0
#2 a f a b 20 10?????????? 20??????????? 0
#3 x m y m 50 30??????????? 0?????????? 30
A.K.

?