[R] Suprising R behaviour

Ilgaz S ilgaz.somer at gmail.com
Fri Nov 13 14:11:35 CET 2015


Hello everybody, I am new to R and I discovered something that suprise me
and I have a question about it.
Today I wanted to return a bit array which represents this:

if( arbitrary point above the line)
     return TRUE
else
     return FALSE

First I tought I would use for loop and access every element of the data.
Then I tend to use lapply function.

At the end, I accidently done that without using any if/else statement. (
or for loop )  Here is the code:

data <- data.frame(x= c(1,2,3,1,1,1), y = c(1,2,3,4,6,7))fin_hyp <-
list(slope=2,constant=1)outputs <- data['y'] > fin_hyp['slope'] *
data['x']  +fin_hyp['constant']outputs

What is R doing here? It is using loop somewhere inside? Is this code
more efficient than other methods I mentioned?

Thank you, I.S.

	[[alternative HTML version deleted]]



More information about the R-help mailing list