jeudi 1 mars 2018

add column values based on other columns in data frame with ifelse

In R, I have a dataset composed of several columns, and the one that interests me is the "electrode" one. I would like to create a new column, called "area", whose containt depends on the electrode. Therefore, I used an ifelse condition, like this:

threeway$area <- ifelse(threeway$electrode %in% c("FZ","FCZ","CZ","CPZ","PZ"),"midline","lateral")

It works good, the new column with adequate containt is created

Then I checked the levels of the column "area", I obtain this, as if there were nothing inside!

levels(threeway$area) 
NULL

Do you know how to resolve this problem?

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire