Sorry to repeat the meassage, not sure if the HTML version has been received - Apologies for duplication

Dear list

I am trying to count the no of occurances in a column of a data frame and there is missing data identifed by NA.

I am able to melt and cast the data correctly as well as sum the occurances using margins and sum.

Here are the melt and cast commands

bw = melt(res, id=c("lab","r"), "pf_zbw")
b = cast(bw, lab ~ r, sum, margins = T)

Sample Data (before using sum and margins)

    lab  1  2  3  4  5  6
1  4er66  1 NA  1  0 NA  0
2  4gcyi  0  0  1  0  0  0
3  5d3hh  0  0  0 NA  0  0
4  5d3wt  0  0  0  0  0  0
.
. lines deleted to save space
.
69 v3st5 NA NA  1 NA NA NA
70 a22g5 NA  0 NA NA NA NA
71 b5dd3 NA  0 NA NA NA NA
72 g44d2 NA  0 NA NA NA NA

Data after using sum and margins

    lab 1 2 3 4 5 6 (all)
1  4er66 1 0 1 0 0 0     2
2  4gcyi 0 0 1 0 0 0     1
3  5d3hh 0 0 0 0 0 0     0
4  5d3wt 0 0 0 0 0 0     0
5  6n44r 0 0 0 0 0 0     0
.
.lines deleted to save space
.
70 a22g5 0 0 0 0 0 0     0
71 b5dd3 0 0 0 0 0 0     0
72 g44d2 0 0 0 0 0 0     0
73 (all) 5 2 4 3 5 7    26

Uisng length just tells me how many total rows there are.

What I need to do is count how many rows there is valid data, in this case either a one (1) or a zero (0) in b

I have a report to construct for tomorrow Mon so any help would be appreciated

Regards
Steve

______________________________________________
R-help@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.

Reply via email to