Skip to content
Prev 30519 / 398513 Next

NA in logical vector = data frame row numbers scrambled

Dear all.

RE how to estimate parameters of multimodal distribution
Thank to prof.Ripley for pointing me to mclust package, although I am not sure I 
can apply it to my problem.

I have another question. 

I need to change some of my values in data frame to NA.

I use something like  
df[df$v1 < 5, 5:10] <- NA 

which is OK if there are no NA values in v1.

here are some foo attempts
index cislo     time den hod min  zatizdp   plyndp  skalice
5      5     1 37693.79  13  19   0 106.6707 533.0288 5.932448
6      6     1 37693.80  13  19  15 106.2308 533.8799 6.008640
7      7     1 37693.81  13  19  30 106.3643 534.5321 5.960807
8      8     1 37693.82  13  19  45 106.9483 533.9640 5.962759
9      9     1 37693.83  13  20   0 106.9289 533.9978 5.939210
10    10     1 37693.84  13  20  15 107.1585 518.3881 5.980370
index cislo     time den hod min  zatizdp   plyndp  skalice
5      5     1 37693.79  13  19   0       NA       NA       NA
6      6     1 37693.80  13  19  15 106.2308 533.8799 6.008640
7      7     1 37693.81  13  19  30 106.3643 534.5321 5.960807
8      8     1 37693.82  13  19  45 106.9483 533.9640 5.962759
9      9     1 37693.83  13  20   0       NA       NA       NA
10    10     1 37693.84  13  20  15 107.1585 518.3881 5.980370

but further on
Error in if (all(i >= 0) && (nn <- max(i)) > nrows) { : 
        missing value where logical needed

the problem is in logical vector having NA
[1]    NA FALSE FALSE FALSE    NA  TRUE

and subsequent scrambled row numbering
zatizdp   plyndp skalice
NA        NA       NA      NA
NA1       NA       NA      NA
X10 107.1585 518.3881 5.98037

Is there some more simple or direct way how to achieve this
index cislo     time den hod min  zatizdp   plyndp skalice
10    10     1 37693.84  13  20  15 107.1585 518.3881 5.98037

to be able to change values in data frame gradually to NA?

Excuse my awkward English. I hope you will understand my problem.
Thanks.

Best regards.

Petr Pikal
petr.pikal at precheza.cz
p.pik at volny.cz