I'm a beginner with R and I have written this simple loop:
for(i in 1:12000){
if(v$piano.tariff[i] == 2) {v$piano.tariff[i] = 0}
else {v$piano.tariff[i] = 1}
}
Where v is a data frame and piano.tariff one of its columns. What the loop does is simply change each value of the piano.tariff column to either 1 or 0, from their initiali values of 2 and 5.
Now, the code works, but the problem is that it is ridiculously slow. It takes up to 4-5 minutes to complete! In C++ o C# such a loop would barely require a few seconds.
Why is this so slow? Is there a faster way to implement this? Or is it simply that R is slow, and that's it?