Hi all,

I'm trying to randomly select sample numbers for length class groups (5 per length class).

For this I'm using a loop FOR and the function sample () and specified a size for the sampling of 5. Unfortunately, one of the length class group does not contain 5 individuals. For me is not a big deal as I have others groups to complete. However it bothers me that the sampling function does not select any individuals in this group generating the error below :

Error in sample(Gpool2$SampleNb[Gpool2$LngtClas == LngtClas[[i]] & Gpool2$SpCode == : can not take a sample larger than the population when 'replace = FALSE'.

I understand why this error message appears but I was wondering if there is a way to select all the items present in the group even if it's not 5 (something like size =< 5).

LngtClas <- list( "40_49", "50_59", "60_69", "70_")
SpCode <- list ("POLLVIR ", "MERLMER")

a <- as.character(sample(Gpool$SampleNb[Gpool$LngtClas == LngtClas[[4]] & Gpool$SpCode == SpCode[[2]]], size = 5, replace = FALSE))

You can find enclosed my dataset,

Thank you for the help,

Xochitl C.

<>< <>< <>< <><

Xochitl CORMON
+33 (0)3 21 99 56 84

Doctorante en sciences halieutiques
PhD student in fishery sciences

<>< <>< <>< <><

IFREMER
Centre Manche Mer du Nord
150 quai Gambetta
62200 Boulogne-sur-Mer

<>< <>< <>< <><

SampleNb,SpCode,LngtClas
3,MERLMER,40_49
5,POLLVIR ,50_59
6,POLLVIR ,50_59
13,POLLVIR ,60_69
19,MERLMER,40_49
20,MERLMER,50_59
21,POLLVIR ,60_69
22,POLLVIR ,50_59
23,MERLMER,60_69
24,POLLVIR ,40_49
25,POLLVIR ,40_49
30,POLLVIR ,50_59
31,POLLVIR ,40_49
32,MERLMER,60_69
33,POLLVIR ,40_49
34,MERLMER,40_49
35,POLLVIR ,60_69
36,POLLVIR ,60_69
37,POLLVIR ,40_49
38,MERLMER,40_49
39,POLLVIR ,40_49
40,MERLMER,60_69
44,MERLMER,70_
45,POLLVIR ,70_
62,POLLVIR ,70_
63,MERLMER,70_
74,MERLMER,40_49
75,POLLVIR ,50_59
76,MERLMER,50_59
77,MERLMER,50_59
78,POLLVIR ,60_69
79,POLLVIR ,60_69
96,MERLMER,70_
97,POLLVIR ,70_
104,MERLMER,50_59
105,POLLVIR ,50_59
112,MERLMER,50_59
113,POLLVIR ,60_69
114,POLLVIR ,60_69
115,MERLMER,50_59
116,MERLMER,60_69
117,POLLVIR ,60_69
128,MERLMER,60_69
129,POLLVIR ,70_
130,MERLMER,60_69
131,POLLVIR ,60_69
136,MERLMER,60_69
137,POLLVIR ,60_69
142,POLLVIR ,50_59
143,MERLMER,40_49
______________________________________________
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