I have a very large data set that contains multiple groups. They all contain the same information, however, occasionally and inconsistently, this information is misordered.
In the example below, The Group1_A1
and Group2_A1
columns do not match (Rows 3 & 4 are flipped), therefore the rest of the information in those rows are not comparable. In order to correct this, the BETA of GROUP1_BETA
should be multipled by -1 (again, given that the A1 columns between groups do not match, if they do match, the Beta should remain as it is).
MARKER GROUP1_A1 GROUP1_A2 GROUP1_BETA GROUP1_SE GROUP2_A1 GROUP2_A2 GROUP2_BETA GROUP2_SE
rs10 A C -0.055 0.003 A C 0.056 0.200
rs1000 A G 0.208 0.100 A G 0.208 0.001
rs10000 G C -0.134 0.009 C G -0.8624 0.010
rs10001 C A 0.229 0.012 A C 0.775 0.003
When dealing with frequencies falling between 0-1, I was using:
data$GROUP1_oppositeFrequency <- abs( (as.character(data$Group2_A1) !=
as.character(data$Group1_A1)) -
as.numeric(data$Group1_Frequency) )
however, because Beta values can be negative, this is not going to work. Can anyone point me in the right direction?
Reproducible Data:
data <- textConnection("SNP,GROUP1_A1,GROUP1_A2,GROUP1_Beta,GROUP1_SE,GROUP2_A1,GROUP2_A2,GROUP2_Beta,GROUP2_SE,GROUP3_A1,GROUP3_A2,GROUP3_Beta,GROUP3_SE
rs1050,C,T,0.0462,0.0035,T,C,0.007,0.0039,C,T,-0.007,0.009
rs1073,A,G,-0.0209,0.0035,A,G,0.0004,0.0031,A,G,-0.009,0.013
rs1075,C,T,-0.001,0.0039,T,C,-0.0013,0.0028,C,T,0.004,0.011
rs1085,C,G,-0.0001,0.0068,C,G,-0.0027,0.0032,C,G,-0.049,0.026
rs1127,C,T,0.0015,0.0044,T,C,0.0002,0.0029,C,T,-0.017,0.009
rs1312,A,G,-0.0014,0.0039,A,G,-0.0025,0.0029,A,G,0,0.01")
test_data <- read.csv(data, header = TRUE, sep = ",")