The length will remain the same no matter what expression appears in the subscript. I suggest this:
sum(x == 1) David Reinke Senior Transportation Engineer/Economist Dowling Associates, Inc. 180 Grand Avenue, Suite 250 Oakland, California 94612-3774 510.839.1742 x104 (voice) 510.839.0871 (fax) www.dowlinginc.com Please consider the environment before printing this e-mail. Confidentiality Notice: This e-mail message, including any attachments, is for the sole use of the intended recipient(s), and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message. -----Original Message----- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Randall Wrong Sent: Friday, February 26, 2010 6:44 AM To: r-help@r-project.org Subject: [R] counting the number of ones in a vector Dear R users, I want to count the number of ones in a vector x. That's what I did : length( x[x==1] ) Is that a good solution ? Thank you very much, Randall [[alternative HTML version deleted]] ______________________________________________ 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. ______________________________________________ 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.