[R] Calculate NAs from known data: how to?

Torleif Markussen Lunde tlu004 at student.uib.no
Tue Oct 17 12:10:40 CEST 2006


Hi

In a dataset I have length and age for cod. The age, however, is ony 
given for 40-100% of the fish. What I need to do is to fill inn the NAs 
in a correct way, so that age has a value for each length. This is to be 
done for each sample seperately (there are 324 samples), meaning the NAs 
for sampleno 1 shall be calculated from the known values from sampleno 1.

As for example length 55 cm can be both 4 and 5 years, I guess a fish 
with NA age and length 55 cm should be given a "random" age given a 
probability for example "55 cm = 4 years has a p=75%, while 55 cm = 4 
years has a p=25%". Those "p-values" should be calculated from the real 
data.

How can this be done in R, and what is the right way to do it?

Sample number 1 is given below.

Best regards
Torleif Markussen Lunde

length	age	sampleno
55	5	1
45	4	1
55	4	1
55	5	1
60	6	1
45	5	1
52	5	1
48	4	1
51	6	1
53	4	1
54	5	1
48	5	1
50	6	1
55	6	1
55	4	1
50	5	1
49	5	1
40	4	1
50	6	1
36	4	1
46	6	1
35	3	1
41	3	1
44	5	1
36	3	1
29	2	1
28	2	1
32	2	1
31	2	1
30	2	1
29	2	1
32	2	1
28	2	1
25	2	1
27	2	1
27	2	1
24	2	1
27	2	1
24	2	1
19	1	1
23	1	1
23	1	1
20	1	1
23	1	1
19	1	1
17	1	1
53	5	1
58	5	1
52	4	1
42	3	1
50	5	1
94	7	1
35	3	1
71	7	1
52	6	1
50	6	1
45	4	1
52	5	1
37	3	1
45	4	1
59	5	1
47	4	1
48	4	1
39	3	1
37	3	1
31	3	1
39	2	1
39	2	1
31	2	1
40	3	1
52	5	1
62	5	1
72	5	1
53	5	1
61	5	1
54	6	1
54	5	1
63	6	1
58	5	1
45	4	1
43	4	1
55	4	1
39	3	1
39	3	1
58	5	1
65	6	1
52	6	1
48	3	1
49	3	1
44	3	1
45	4	1
35	2	1
38	3	1
30	2	1
29	1	1
27	1	1
44	NA	1
48	NA	1
37	NA	1
27	NA	1
30	NA	1
67	NA	1
28	NA	1
65	NA	1
42	NA	1
27	NA	1
37	NA	1
30	NA	1
28	NA	1
26	NA	1
36	NA	1
29	NA	1
32	NA	1
45	NA	1
39	NA	1
27	NA	1
29	NA	1
28	NA	1
27	NA	1
53	NA	1
21	NA	1
15	NA	1
23	NA	1



More information about the R-help mailing list