[問題] 如何快速mutate多行?

作者: s3714443 (metalheads)   2017-08-28 02:00:11
小弟又來請教問題
mutate(.,MA10t=SMA(Ct,10),
MA10lower=as.numeric(Ct<MA10t),
MA10down=as.numeric(MA10lower==1&lag(MA10lower)==0),
MA10down1=ifelse(lead(MA10down,1)==0,0,lead(Ct,1)),
MA10down2=ifelse(lead(MA10down,2)==0,0,lead(Ct,2)),
MA10down3=ifelse(lead(MA10down,3)==0,0,lead(Ct,3)),
MA10down4=ifelse(lead(MA10down,4)==0,0,lead(Ct,4)),
MA10down5=ifelse(lead(MA10down,5)==0,0,lead(Ct,5)),
MA10down6=ifelse(lead(MA10down,6)==0,0,lead(Ct,6)),
MA10down7=ifelse(lead(MA10down,7)==0,0,lead(Ct,7)),
MA10down8=ifelse(lead(MA10down,8)==0,0,lead(Ct,8)),
MA10down9=ifelse(lead(MA10down,9)==0,0,lead(Ct,9)))
請問各位 我想要創建column 直到
MA10down60=ifelse(lead(MA10down,60)==0,0,lead(Ct,60))
不知是否有什麼好方法呢?
再者有個情況是
pmin(MA10down1,MA10down2,MA10down3,MA10down4,
MA10down5,MA10down6,MA10down7,MA10down8,MA10down9,MA10down10...MA10down60)
有什麼方法可以巧妙把60個用精簡的語法一次選取起來?
感謝各位QQ
作者: celestialgod (天)   2017-08-28 19:11:00
看不懂你要幹嘛... 有沒有input根output的例子

Links booklink

Contact Us: admin [ a t ] ucptt.com