[R] R Error : DATA to MATRIX
Petr PIKAL
petr.pikal at precheza.cz
Mon Mar 26 16:02:25 CEST 2012
>
> On similar lines, how do I assign the position of the an occurence of a
> value say 7 in a data vector to another data vector?
>
> > nFields
> [1] 6 6 6 6 6 6 7 7 6 6 6 7 6 6 6 6
> I need the output data vector showing occurence of 7 as:
> [1] 7 8 12
which(nFields==7)
Regards
Petr
>
> I tried following but both has errors
> xFields7 <- NULL
> for (i in 1:length(nFields)) {
> c(xFields7,ifelse(nFields[i] == 7,i,NULL)) -> xFields7
> }
>
> xFields7 <- NULL
> for (i in 1:length(nFields)) {
> if nFields[i] == 7 then c(xFields7,i) -> xFields7
> }
>
>
More information about the R-help
mailing list