4
I have a dataframe with 20 students and I need to identify the students who attended stage 43 for two years or more.
aluno <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)
etapa_2012 <- c(42, 43, 44, 43, 42, 43, 44, 45, 42, 43, 44, 45, 42, 43, 44, 44, 42, 43, 44, 45)
etapa_2013 <- c(43, 44, 45, 43, 43, 44, 45, 45, 43, 43, 45, 45, 43, 44, 45, 44, 43, 44, 45, 45)
etapa_2014 <- c(44, 45, 45, 43, 44, 45, 45, 45, 44, 43, 45, 45, 44, 45, 45, 45, 44, 45, 45, 45)
etapa_2015 <- c(45, 45, 45, 44, 45, 45, 45, 44, 43, 45, 45, 45, 45, 45, 45, 44, 43, 45, 45, NA)
fluxo<-data.frame(aluno, etapa_2012, etapa_2013, etapa_2014, etapa_2015)
But I can only add a new column identifying the students who did step 43.
fluxo$dois_ou_mais <-ifelse(fluxo$etapa_2012==43|fluxo$etapa_2013==43|fluxo$etapa_2014==43|fluxo$etapa_2015==43, 1, 0)
fluxo
I would like to arrive at the result where only students 4, 9, 10 and 17 were marked in the column dois_ou_mais, since they have stage 43 in more than a year, as shown below.
By the way, why don’t you
as.integer
?– Rui Barradas
I may be mistaken, but I believe there is no practical difference between
as.integer
andas.numeric
in theR
if numerical values are used within theR
. If I needed to pass the result of this command to a C program, it would make a difference to turn the data into integer or floating point. Inside theR
I guess it doesn’t matter if you use one function or the other.– Marcus Nunes