Created
April 9, 2017 10:07
-
-
Save rosdyana/828c9fa3023de2c4fcaf9a38f9f4e2fc to your computer and use it in GitHub Desktop.
s1056035_HW_1_BDA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/Rscript | |
# Name : Rosdyana Kusuma | |
# Student ID : s1056035 | |
# mail : [email protected] , [email protected] | |
# site : rosdyanakusuma.com | |
# read input data. | |
dataInput = read.csv("input.csv", header=F , sep=",") | |
# create confusion matrix. | |
table <- table(dataInput[,1],dataInput[,2]) | |
x = table | |
# check the matrix result | |
x | |
# init | |
appliedCol = NULL | |
maxVal = max(x) | |
minVal = min(x) | |
# re-position the highest value in column based on their row position. | |
# my codes isn't optimize, its ugly codes | |
for(a in maxVal:minVal) | |
{ | |
# check value is exist or not | |
if( a %in% x){ | |
# get current position | |
CurPos = which(x[,] == a, arr.ind=T) | |
# extract the postion | |
RowPos = CurPos[1] | |
ColPos = CurPos[2] | |
if(any(appliedCol==ColPos) ){ | |
print("column fixed") | |
} else { | |
if(is.null(appliedCol) || !(RowPos %in% appliedCol) ){ | |
print("moved to new column") | |
x[ , c(ColPos,RowPos)] <- x[ , c(RowPos,ColPos)] | |
appliedCol = append(appliedCol,RowPos) | |
} else { | |
print("column already assigned") | |
} | |
} | |
print(x) | |
} | |
} | |
# check the matrix result | |
x | |
# write into output.csv | |
write.table(x, file="output.csv",col.names=F,row.names=F,sep = ",") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment