[R] Missing Values in Table Statement

MacQueen, Don macqueen1 at llnl.gov
Fri Jun 12 19:28:59 CEST 2015


Maybe it will help if I create some fake data to illustrate what I think
you want:

set.seed(25)
tmp <- data.frame(origin=sample( letters[1:3], 25, replace=TRUE),
                  schd= sample( 1:5, 25, replace=TRUE)
                  )
tmp$schd[ c(5,7,18,22) ] <- NA

print(tmp)


table( tmp$origin, is.na(tmp$schd))
   
    FALSE TRUE
  a     9    1
  b     6    2
  c     6    1




## a little fancier

table( tmp$origin, ifelse(is.na(tmp$schd),'missing','available'))
   
    available missing
  a         9       1
  b         6       2
  c         6       1



For example, for schedule "b" there are 6 instances for which the sched
time has been entered and 2 where it has not.


In this example, the table() function is working correctly.

I don't think anyone understands what is wrong with the output you are
getting.

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 6/11/15, 11:27 PM, "Shivi82" <shivibhatia at ymail.com> wrote:

>Hi Petr,
>
>Probably i did not explain my scenario clearly.
> table(test$ORIGIN_NAME,is.na(test$SCH_TIME)) is the syntax with which i
>am
>trying to find per destination wise how many instances are there where
>system failed to enter the scheduled delivery time & there are multiple
>cases of these. I am expecting an output where TRUE and FALSE will give
>number of observations either missing or non-missing.
>
>ORIGIN         ORIGIN_NAME DESTINATION      DESTINATION_NM  RPS_NO
>DLI11            DELHI-11       NDA50                  NOIDA-50
> 
>1350760
>NDA50            NOIDA-50     DLI11                    DELHI-11
> 
>1352692 
>
>
>SCH_TIME  ACTUAL_DEP_DATE ACTUAL_DEP_TIME WAYBILLS TOTAL_PKG ACTUAL_WT
>CHG_WT
>6:00         13/03/2015                    6:30                      -
>      
>0                  0                0
>21:30       15/03/2015                   13:37                     28
>  
>256           3419               3730
>
>
>Hopefully i am able to make my self now clear. Thank you.
>
>
>
>
>
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/Missing-Values-in-Table-Statement-tp4708534p
>4708537.html
>Sent from the R help mailing list archive at Nabble.com.
>
>______________________________________________
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>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.



More information about the R-help mailing list