lundi 3 décembre 2018

programming R ifelse , take previous row

Hello i need help with programming R. I have data.frame B with two column

x<- c(1,2,1,2,1,2,1,2,1,2,1,2,.......etc.)
y<-c(M,P,P,M,S,M,M,S,P,S,P,M,...)

2 milion rows and i need create next columns . Next columns should look as

z<-c(M,MP,P,PM,S,SM,M,MS,P,PS,P,PM,....)

when is x==2 that take previous rows in y and paste with y in X==2. I use base package.

I do not want to use cycle- loop.

Aucun commentaire:

Enregistrer un commentaire