forked from wangzichan/550400.github
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomputepair.R
53 lines (48 loc) · 1.55 KB
/
computepair.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
system("ls -1F | grep '/$' > studentnames.txt");
folders = read.table('studentnames.txt');
folders = folders[[1]];
folders = as.character(folders);
randomize = sample(1:18,18,replace=FALSE)
folders = folders[randomize]
nfolders = length(folders)
for(itr.i in 1:(nfolders-1)) {
for(itr.j in (itr.i+1):nfolders) {
folder1 = folders[itr.i]
folder2 = folders[itr.j]
#sout = paste(folder1,'_vs_',folder2,'\n',sep='')
#cat('\n$', sout,'')
filename1 = paste(folder1,'my1rpack/R/problem1.R',sep='')
filename2 = paste(folder2,'my1rpack/R/problem1.R',sep='')
bashcmd = paste('diff ',filename1,' ',filename2,' ',sep='')
output = system(bashcmd)
cat('\n')
bashcmd = paste('diff ',filename1,' ',filename2,' | wc -l >> result.txt',sep='')
output = system(bashcmd)
bashcmd = paste('wc -l ',filename1,sep='')
output = system(bashcmd)
bashcmd = paste('wc -l ',filename2,sep='')
output = system(bashcmd)
scan() #use CTRL-C to break out
}
}
output = read.table('result.txt')
output = output[[1]]
result = matrix(0,nrow=nfolders,ncol=nfolders)
count = 0
for(itr.i in 1:(nfolders-1)) {
for(itr.j in (itr.i+1):nfolders) {
count = count + 1
result[itr.i,itr.j] = output[count]
}
}
result = result + t(result)
require(lattice)
graphics.off()
dev.new()
levelplot(result,main='Dissimilarity Matrix')
dev.new()
reduced = cmdscale(result)
plot(reduced)
xval = reduced[,1]+runif(18,-5,5)
yval = reduced[,2]+runif(18,-5,5)
text(xval.j,yval,1:18,cex=.5)