lundi 27 juillet 2015

categorze a Data frame in base another data frame in R

I am trying to add a vector category (let's say objetive or ignore) in a data frame. My data frame contain 3 variables (quantity, time and cell), and I want to create a new data frame for time=1 and give the category in base of the value of quantity.Then, I woul like to extend that category to the rest of the data frame keeping that category regarding the change in the value of quantity.

Here is a example code:

raw<- seq(from = 1,to=10,by=1)
raw<-c(raw,raw,raw,raw,raw)

time <- raw[order(raw)] 
quantity<-rnorm(n = length(time),mean = 1,sd = 0.2
)
cell<-c("A","B","C","D","E")
cell<-c(cell,cell,cell,cell,cell,cell,cell,cell,cell,cell)

data<-data.frame(time, quantity, cell)

start<-filter(.data = data, data$time==1)

start$group<-ifelse (start$quantity>1,yes="objetive",
                     no  = "ignore")
start

data

Best

Aucun commentaire:

Enregistrer un commentaire