jeudi 31 décembre 2015

if ifelse or what else?

I have a problem I couldn't find an answer to. Let's say I have the following:

x <- seq(1,1000,0.1)
y <- seq(1,1000,0.1)
a <- rnorm(100,50,5)
df <- data.frame(a)

and I want to loop over every line in my data frame and evaluate if it meets two conditions.

df$a[i] > x/2 & df$a[i] <= log(x) 
df$a[i] < log2(x)

For each condition I want to indicate the result in a new column on my data frame. I know that if statements can't go over vectors and ifelse takes one condition. My original problem is how to assign data in a graph based on fitted curve.

Aucun commentaire:

Enregistrer un commentaire