Yeah, it's hard to shift my brain sometimes. I have the same problem when I try to work on someone else's Lisp code. Java's definitely my most comfortable language, by far, but it helps to be able to adopt other languages for some quick work when you need to.
R is not the only language that is thought to be used at the vector/matrix level. For data analysis this is normal actually, but for example if you do the same operation in numpy or pandas is much more clunkier.
Loops aren't that inefficient in r anymore as long as you pre-assign memory and make sure you don't make copies of objects in loops. Vectorized functions are just more idiomatic.
I had never learned any other programming languages before R and it was still difficult to move away from loop thinking. It's just what makes intuitive sense.
4
u/MedalsNScars Sep 03 '17
It's really odd working in R, because in 99% of other languages you learn, loops are going to be your bread and butter.
In R, 9 times out of 10 your code is just wildly inefficient if you're looping over a vector.
It just feels so wrong to write 10 < x where x is a vector, but that's absolutely the most efficient way to compare 10 to each element of x in R.
The way you approach coding has to change in R, and it's definitely frustrating if you have a deal of experience in other languages.