I have a txt file (data5.txt):
1 0 1 0 0
1 1 1 0 0
0 0 1 0 0
1 1 1 0 1
0 0 0 0 1
0 0 1 1 1
1 0 0 0 0
1 1 1 1 1
0 1 0 0 1
1 1 0 0 0
I need to count the frequency of one's and zero's in each column
if the frequency of ones >= frequency of zero's then I will print 1 after the last row for that Colum
I'm new in R, but I tried this, and I got error:
Error in if (z >= d) data[n, i] = 1 else data[n, i] = 0 :
missing value where TRUE/FALSE needed
my code:
data<-read.table("data5.txt", sep="")
m =length(data)
d=length(data[,1])/2
n=length(data[,1])+1
for(i in 1:m)
{
z=sum(data[,i])
if (z>=d) data[n,i]=1 else data[n,i]=0
}
1,2,5,8
1,3,5,9
2,5,9,11
2,4,5,8
2,4,5,9
So, what I did is: I applied clustering method (I used: pam), where the number of clusters =2, and the similarity function is jaccard. After clustering: I got in txt file:
“x”
“1” 1
“2” 1
“3” 2
“4” 2
“5” 2
Which means: the 1st , and 2nd transactions are in cluster number 1, where the 3rd, 4th, and 5th transactions are in cluster 2 – Meem Nov 10 '13 at 23:22
C1, 1,2,5,8
C1, 1,3,5,9
C2, 2,5,9,11
C2, 2,4,5,8
C2, 2,4,5,9
– Meem Nov 10 '13 at 23:24