Java Mailing List Archive

http://www.r-help.com/

Home » R Help for Statistical Computing »

[R] as.integer and indexes error

Lilia Leticia Ramírez Ramírez

2010-03-11

Replies: Find Java Web Hosting

Author LoginPost Reply
Hello All,

I would like to report the following bug or maybe you can explain if I am
wrong.

I am sampling from two different populations with weights. The two
populations have the same age groups and I want to distinguish where I am
sampling from. That is why I am using a matrix such as:
matrix
age.group    Male       Females     Weight.Males   Weight.Females
1          1.1             1.2
3                       4
2          2.1             2.2
6                       5
3          3.1              3.2
3                         5
4          4.1              4.2
9                       2

If a sample a element:
uno<-sample(matrix[,2:3],1,prob=matrix[,4:5])
I want to be able to recover from wich age.group and sex the individual is,
but

as.integer((uno-round(uno))*10) is equal to 0 when uno is male, while it is
2 when a female. That is, for example:

as.integer((4.1-round(4.1))*10) is equal to 0 (instead of 1)

The rounding error is eliminated for
as.integer((uno[j,2]-round(uno))*11) since it is equal to 1 when male and
2 when female.

I noticed this problem when trying to use

other.matrix[j, (uno[j,2]-round(uno))*10)]

for a matrix with information with first information about males and second
column about females.

Thank you kindly.
Lilia

 [[alternative HTML version deleted]]

______________________________________________
R-help@(protected)
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.
©2008 r-help.com - Jax Systems, LLC, U.S.A.