I have the following txt file:
Test-case: 1 --------------------
int int0 = (-1790);
String string0 = "14_d4BWMJqn";
MethodVisitor methodVisitor0 = mock(MethodVisitor.class, new ViolatedAssumptionAnswer());
MethodAdapter methodAdapter0 = new MethodAdapter(methodVisitor0);
int int1 = 4073;
Label label0 = new Label();
methodAdapter0.visitLabel(label0);
String string1 = "H*";
String string2 = "5^?5P\"#V\"c<_yB";
methodAdapter0.visitFieldInsn(int1, string0, string1, string2);
LocalVariablesSorter localVariablesSorter0 = new LocalVariablesSorter(int0, string0, methodAdapter0);
localVariablesSorter0.visitVarInsn(int0, int0);
Attribute attribute0 = mock(Attribute.class, new ViolatedAssumptionAnswer());
methodAdapter0.visitAttribute(attribute0);
int int2 = (-2549);
int int3 = 4149;
localVariablesSorter0.visitVarInsn(int2, int3);
int int0 = (-1790);
localVariablesSorter0.visitMaxs(int2, int2);
I would like to count how many each line appears in the text file (the occurrences of each line in the file). To do that:
con = file("/home/adam/Desktop/Trash/qwe.txt", "r")
lines <- readLines(con)
data_per_class1 <- data.frame(Statement = NA, Freq = NA)
x <- 1
for(i in 1:length(lines)){
frq <- length(grep(lines[i], lines))
data_per_class1[x,] <- c(lines[i], frq)
x <- x + 1
}
print(data_per_class1)
close(con)
The results that I got is:
The results are wrong. Each line should at least has frequency of 1. Also, there is one line that has frequency of 2 which is int int0 = (-1790);
but it is given frequency of zero. I think the problem with this grep(lines[i], lines)
Can you please help solving this issue?