[R] R Error : DATA to MATRIX

Berend Hasselman bhh at xs4all.nl
Mon Mar 26 11:53:02 CEST 2012


On 26-03-2012, at 11:34, Ashish Agarwal wrote:

> 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
> 
> 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
> }


?which

Berend



More information about the R-help mailing list