[R] NA or work around ??

Henrique Dallazuanna wwwhsd at gmail.com
Wed Dec 30 18:09:07 CET 2009


Try this:

Dataset$LLCI<-with(Dataset, ave(Rcil, LEAID, Property, FUN =
function(x)max(x, na.rm = TRUE)))

On Wed, Dec 30, 2009 at 2:44 PM, L.A. <romsa at millect.com> wrote:
>
>
> I've searched and tried several ideas (na.action. and other things), but I
> can't see
> to figure this out.
> I'm guessing this is so simple I'll feel foolish for asking, but here goes.
> Thanks,
> L.A.
>
> Dataset$Rcil=with(Dataset, ifelse(Rpr >= .95, Dataset[,"percentchgn"], NA))
>
> Dataset$LLCI<-with(Dataset, ave(Rcil, LEAID, Property,
> FUN=function(x)max(x)))
>
>
>    LEAID      percentchgn Property    Rpr      Rcil     LLCI
> 12  2036       12.190220   UNSOLD  0.9999237 12.190220 16.09097
> 13  2036       14.741559   UNSOLD  0.9992714 14.741559 16.09097
> 14  2036       15.882518   UNSOLD  0.9955750 15.882518 16.09097
> 15  2036       16.090965   UNSOLD  0.9807892 16.090965 16.09097
> 34  2201       -6.542363   UNSOLD -1.0000000           NA         NA
> 55  2201       -5.060431   UNSOLD  0.9848659 -5.060431         NA
> 56  2201       -5.056231   UNSOLD  0.9699841 -5.056231         NA
> 57  2201       -4.994895   UNSOLD  0.9441028           NA         NA
> 58  2201       -4.982279   UNSOLD  0.9020456           NA         NA
> 99  2202       -8.982821   UNSOLD -1.0000000          NA          NA
> 241 2202        9.704573   UNSOLD -1.0000000          NA          NA
> 242 2202       10.447709   UNSOLD  0.9999237 10.447709        NA
> 243 2202       12.616943   UNSOLD  0.9992714 12.616943        NA
> 244 2202       12.943887     SOLD  0.9955750 12.943887          NA
> 245 2202       13.774406     SOLD  0.9807892 13.774406          NA
> 246 2202       15.007848     SOLD  0.9364319          NA           NA
> 333 2333        2.099854   UNSOLD  0.7853246         NA           NA
> 333 2333        2.343452   UNSOLD  0.7853246         NA          NA
>
>
> What I'm trying to accomplish is:
>
>    LEAID      percentchgn Property    Rpr      Rcil     LLCI
> 12  2036       12.190220   UNSOLD  0.9999237 12.190220 16.09097
> 13  2036       14.741559   UNSOLD  0.9992714 14.741559 16.09097
> 14  2036       15.882518   UNSOLD  0.9955750 15.882518 16.09097
> 15  2036       16.090965   UNSOLD  0.9807892 16.090965 16.09097
> 34  2201       -6.542363   UNSOLD -1.0000000           NA -5.056231
> 55  2201       -5.060431   UNSOLD  0.9848659 -5.060431 -5.056231
> 56  2201       -5.056231   UNSOLD  0.9699841 -5.056231 -5.056231
> 57  2201       -4.994895   UNSOLD  0.9441028           NA -5.056231
> 58  2201       -4.982279   UNSOLD  0.9020456           NA -5.056231
> 99  2202       -8.982821   UNSOLD -1.0000000          NA 12.616943
> 241 2202        9.704573   UNSOLD -1.0000000          NA 12.616943
> 242 2202       10.447709   UNSOLD  0.9999237 10.447709 12.616943
> 243 2202       12.616943   UNSOLD  0.9992714 12.616943 12.616943
> 244 2202       12.943887     SOLD  0.9955750   12.943887 13.774406
> 245 2202       13.774406     SOLD  0.9807892   13.774406 13.774406
> 246 2202       15.007848     SOLD  0.9364319             NA 13.774406
> 333 2333        2.099854   UNSOLD  0.7853246            NA        NA
> 333 2333        2.343452   UNSOLD  0.7853246            NA        NA
> --
> View this message in context: http://n4.nabble.com/NA-or-work-around-tp991019p991019.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O




More information about the R-help mailing list