3
I need to create the vector fixo
of NA
and 0
from another vector coef
.
If
coef<-c(1,4,10)
then
fixo = (NA,0,0,NA,0,0,0,0,0,NA)
I tried to use str_detect
:
num<-c(1,4,10)
maiorn <- max(num)
A<-seq(1:maiorn)
for (i in 1:maiorn) {
ifelse(str_detect(A[i], num),
A[i]<-"NA",
A[i]<-0)
}
But it didn’t work. The str_detect
finds only strings. Has some function as contained or other way to do this?
excellent, very elegant.
– Rildo