I know that using for-loop in R is often unnecessary as it supports vectorization. I want to program as efficient as possible, there for my question regarding the following code example.
I have a hexagonal grid, and I calculate the number of cells, this number is from 1 to 225 in my example, starting from the lower left corner, and goes to the right. Thus, cell 16 is placed with a bit offset directly above cell 1. see snapshot: 
Therefore, if I have a Y coordinate, the X coordinate should be either rounded or ceiling. In my application, the user indicates the cells, I also save this in the for loop, passing through the cells to determine the cells that he selected, as follows, with the input values ββof the toys for Xcells and Ycells that the user would select:
gridsize <- 15 Xcells <-c(0.8066765, 1.8209879, 3.0526517, 0.5893240) Ycells <-c(0.4577802, 0.4577802, 0.5302311, 1.5445425) clicks <- length(Xcells) cells <-vector('list', clicks)
This corresponds to cell 1 2 3 and 16. 4 clicks. Now, to determine the cell numbers:
Y <- ceiling(Ycells) for(i in 1:clicks){ if(Y[i]%%2==1){ X[i] <- round(Xcells[i]) } else{ X[i]<- ceiling(Xcells[i]) }
So, if Y is βeven,β X should be rounded, and if Y is βnot even,β that should be the ceiling value.
Is there a way to do this without a for loop using a vector?