使用tapply的数据帧到矩阵转换将零转换为NA

时间:2017-10-20 01:11:32

标签: r dataframe matrix na tapply

我需要将数据帧转换为矩阵,我使用以下代码:

LoggAbundTGLMSOagg <- tapply(AbundTGLMSOagg$occurrence,list(AbundTGLMSOagg$plot,AbundTGLMSOagg$species),mean)

我得到了所需的矩阵格式,但零变成了NA。使用tapply(),我如何保留零?

我可以写一个csv文件

write.csv(LoggAbundTGLMSOagg, "LoggAbundTGLMSOagg.csv", na="0", row.names=TRUE)

并将其读回R中,但肯定会有更优雅的解决方案。

非常感谢您的任何建议。

这是我的数据:

> dput(AbundTGLMSOagg)
structure(list(plot = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 
8L, 8L, 8L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 11L, 11L, 
11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 12L, 
13L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 14L, 14L, 15L, 15L, 15L, 
15L, 15L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 
16L, 16L, 16L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 18L, 18L, 18L, 
18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 19L, 19L, 19L, 19L, 19L, 
19L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 
20L, 20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 
21L, 21L, 21L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 24L, 24L, 24L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 25L, 26L, 26L, 26L, 26L, 26L, 26L, 
26L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 28L, 28L, 28L, 28L, 
28L, 29L, 29L, 29L, 29L, 30L, 30L, 30L, 30L, 31L, 31L, 31L, 31L, 
31L, 31L, 31L, 31L, 32L, 32L, 32L, 32L, 32L, 32L, 32L, 33L, 33L, 
33L, 33L, 33L, 33L, 34L, 34L, 34L, 34L, 34L, 34L, 35L, 35L, 35L, 
35L, 35L, 35L, 35L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 36L, 
37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 37L, 38L, 38L, 38L, 
38L, 38L, 38L, 38L, 38L, 38L, 38L, 38L, 39L, 39L, 39L, 39L, 39L, 
39L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 40L, 41L, 41L, 41L, 
41L, 41L, 41L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 42L, 
43L, 43L, 43L, 43L, 43L, 43L, 43L, 43L, 44L, 44L, 44L, 44L, 45L, 
45L, 45L, 45L, 46L, 46L, 46L, 46L, 46L, 46L, 46L, 46L, 46L, 47L, 
47L, 47L, 47L, 47L, 47L, 47L, 47L, 48L, 48L, 48L, 48L, 48L, 48L, 
48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 48L, 49L, 
49L, 49L, 49L, 49L, 49L, 49L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 
50L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 51L, 52L, 52L, 52L, 52L, 
52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 52L, 53L, 53L, 53L, 
53L, 53L, 53L, 53L, 53L, 53L, 53L, 53L, 54L, 54L, 54L, 54L, 54L, 
54L, 54L, 54L, 54L, 54L, 54L, 54L, 54L, 54L, 55L, 55L, 55L, 55L, 
55L, 55L, 55L, 55L, 55L, 55L, 55L, 55L, 55L, 55L, 55L, 56L, 56L, 
56L, 56L, 56L, 56L, 56L, 56L, 56L, 57L, 57L, 57L, 57L, 57L, 57L, 
57L, 57L, 57L, 57L, 57L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 58L, 
58L, 58L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 59L, 60L, 
60L, 60L, 60L, 60L, 60L, 60L, 60L, 60L, 61L, 61L, 61L, 61L, 61L, 
61L, 61L, 61L, 61L, 61L, 61L, 61L, 62L, 62L, 62L, 62L, 62L, 62L, 
62L, 62L, 62L, 63L, 63L, 63L, 63L, 63L, 63L, 63L, 64L, 64L, 64L, 
64L, 64L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 65L, 66L, 
66L, 66L, 66L, 66L, 66L, 66L, 66L, 67L, 67L, 67L, 67L, 67L, 67L, 
67L, 68L, 68L, 68L, 68L, 68L, 68L, 68L, 69L, 69L, 69L, 69L, 69L, 
69L, 69L, 70L, 70L, 70L, 70L, 70L, 70L, 71L, 71L, 71L, 71L, 71L, 
71L, 71L, 71L, 71L, 71L, 72L, 72L, 72L, 72L, 72L, 72L, 72L, 73L, 
73L, 73L, 73L, 73L, 73L, 73L, 73L, 73L, 74L, 74L, 74L, 74L, 74L, 
74L, 74L, 74L, 75L, 75L, 75L, 75L, 75L, 75L, 76L, 76L, 76L, 76L, 
76L, 76L, 77L, 77L, 77L, 77L, 77L, 77L, 77L, 78L, 78L, 78L, 78L, 
78L, 78L, 79L, 79L, 79L, 79L, 79L, 79L, 79L, 79L, 79L, 80L, 80L, 
80L, 80L, 80L, 81L, 81L, 81L, 81L, 82L, 82L, 82L, 82L, 82L, 82L, 
82L, 83L, 83L, 83L, 83L, 83L, 83L, 83L, 84L, 84L, 84L, 84L, 84L, 
84L, 84L, 84L, 84L, 85L, 85L, 85L, 85L, 85L, 85L, 86L, 86L, 86L, 
86L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 87L, 88L, 88L, 
88L, 88L, 88L, 89L, 89L, 89L, 89L, 89L, 89L, 89L, 89L, 89L, 89L, 
89L, 89L, 90L, 90L, 90L, 90L, 90L, 90L, 90L, 91L, 91L, 91L, 91L, 
91L, 91L, 91L, 91L, 92L, 92L, 92L, 92L, 92L, 92L, 93L, 93L, 93L, 
93L, 93L, 93L, 93L, 93L, 93L, 94L, 94L, 94L, 94L, 94L, 94L, 94L, 
95L, 95L, 95L, 95L, 95L, 95L, 95L, 95L, 95L, 95L, 95L, 96L, 96L, 
96L, 96L, 96L, 96L, 96L, 97L, 97L, 97L, 97L, 97L, 97L, 97L, 97L, 
97L, 97L, 97L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 98L, 
98L, 99L, 99L, 99L, 99L, 99L, 99L, 99L, 99L, 99L, 99L, 99L, 100L, 
100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 101L, 101L, 101L, 
101L, 101L, 101L, 101L, 101L, 101L, 101L, 102L, 102L, 102L, 102L, 
102L, 102L, 102L, 102L, 102L, 103L, 103L, 103L, 103L, 103L, 103L, 
103L, 103L, 104L, 104L, 104L, 104L, 104L, 104L, 104L, 105L, 105L, 
105L, 105L, 105L, 105L, 105L, 105L, 105L, 106L, 106L, 106L, 106L, 
106L, 106L, 106L, 106L, 107L, 107L, 107L, 107L, 107L, 107L, 107L, 
107L, 107L, 107L, 107L, 107L, 107L, 107L, 108L, 108L, 108L, 108L, 
108L, 108L, 108L, 109L, 109L, 109L, 109L, 109L, 109L, 109L, 109L, 
109L, 109L, 109L, 109L, 109L, 110L, 110L, 110L, 110L, 110L, 110L, 
110L, 110L, 110L, 110L, 110L, 110L, 110L, 111L, 111L, 111L, 111L, 
111L, 111L, 111L, 111L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 
112L, 112L, 112L, 113L, 113L, 113L, 113L, 113L, 113L, 113L, 114L, 
114L, 114L, 114L, 114L, 114L, 114L, 114L, 115L, 115L, 115L, 115L, 
115L, 115L, 115L, 115L, 115L, 115L, 116L, 116L, 116L, 116L, 116L, 
116L, 116L, 116L, 116L, 116L, 116L, 116L, 117L, 117L, 117L, 117L, 
117L, 117L, 117L, 117L, 117L, 117L, 118L, 118L, 118L, 118L, 118L, 
118L, 118L, 118L, 118L, 118L, 118L, 118L, 118L, 119L, 119L, 119L, 
119L, 119L, 119L, 119L, 119L, 120L, 120L, 120L, 120L, 120L, 120L, 
121L, 121L, 121L, 121L, 121L, 121L, 121L, 121L, 121L, 121L, 122L, 
122L, 122L, 122L, 122L, 123L, 123L, 123L, 123L, 123L, 123L, 123L, 
123L, 124L, 124L, 124L, 124L, 124L, 124L, 124L, 124L, 125L, 125L, 
125L, 125L, 125L, 125L, 125L, 125L, 126L, 126L, 126L, 126L, 126L, 
126L, 126L, 126L, 127L, 127L, 127L, 127L, 127L, 127L, 128L, 128L, 
128L, 128L, 128L, 128L, 128L, 129L, 129L, 129L, 129L, 129L, 129L, 
129L, 129L, 129L, 129L, 130L, 130L, 130L, 130L, 130L, 130L, 130L, 
130L, 130L, 131L, 131L, 131L, 131L, 131L, 131L, 131L, 132L, 132L, 
132L, 132L, 132L, 132L, 132L, 133L, 133L, 133L, 133L, 133L, 133L, 
133L, 133L, 134L, 134L, 134L, 134L, 134L, 134L, 135L, 135L, 135L, 
135L, 135L, 135L, 135L, 135L, 135L, 135L, 135L, 135L, 135L, 135L, 
135L, 135L, 135L, 135L, 136L, 136L, 136L, 136L, 136L, 136L, 136L, 
137L, 137L, 137L, 137L, 137L, 137L, 137L, 137L, 138L, 138L, 138L, 
138L, 138L, 138L, 138L, 139L, 139L, 139L, 139L, 139L, 139L), .Label = c("H01", 
"H02", "H03", "H04", "H05", "H06", "H07", "H08", "H09", "H10", 
"H11", "H12", "H13", "H14", "H15", "H16", "H17", "H18", "H19", 
"H20", "H21", "H22", "H23", "H24", "H25", "H26", "H27", "H28", 
"H29", "H30", "H31", "H32", "H33", "H34", "H35", "H36", "H37", 
"H38", "H39", "H40", "H41", "H42", "H43", "H44", "H45", "H46", 
"H47", "H48", "H49", "L01", "L02", "L03", "L04", "L05", "L06", 
"L07", "L08", "L09", "L10", "L11", "L12", "L13", "L14", "L15", 
"L16", "L17", "L18", "L19", "L20", "L21", "L22", "L23", "L24", 
"L25", "L26", "L27", "L28", "L29", "L30", "L31", "L32", "L33", 
"L34", "L35", "L36", "L37", "L38", "L39", "L40", "L41", "L42", 
"L43", "L44", "L45", "O01", "O02", "O03", "O04", "O05", "O06", 
"O07", "O08", "O09", "O10", "O11", "O12", "O13", "O14", "O15", 
"O16", "O17", "O18", "O19", "O20", "O21", "O22", "O23", "O24", 
"O25", "O26", "O27", "O28", "O29", "O30", "O31", "O32", "O33", 
"O34", "O35", "O36", "O37", "O38", "O39", "O40", "O41", "O42", 
"O43", "O44", "O45"), class = "factor"), species = structure(c(26L, 
42L, 46L, 47L, 48L, 50L, 52L, 53L, 62L, 20L, 50L, 61L, 62L, 4L, 
20L, 26L, 34L, 37L, 46L, 50L, 52L, 53L, 56L, 58L, 61L, 62L, 20L, 
50L, 62L, 13L, 20L, 50L, 53L, 61L, 4L, 20L, 34L, 35L, 46L, 50L, 
58L, 61L, 62L, 4L, 13L, 20L, 50L, 56L, 61L, 62L, 8L, 20L, 39L, 
40L, 47L, 50L, 57L, 59L, 10L, 34L, 36L, 50L, 59L, 1L, 6L, 39L, 
60L, 8L, 29L, 40L, 46L, 47L, 50L, 51L, 52L, 4L, 8L, 29L, 40L, 
47L, 50L, 62L, 7L, 8L, 14L, 29L, 40L, 47L, 50L, 52L, 2L, 23L, 
2L, 12L, 22L, 30L, 33L, 47L, 50L, 53L, 62L, 6L, 7L, 8L, 12L, 
15L, 20L, 29L, 39L, 40L, 47L, 50L, 52L, 62L, 7L, 12L, 50L, 62L, 
5L, 8L, 14L, 29L, 39L, 40L, 44L, 47L, 50L, 52L, 62L, 4L, 8L, 
10L, 13L, 28L, 47L, 50L, 52L, 53L, 62L, 6L, 8L, 10L, 29L, 39L, 
40L, 44L, 46L, 47L, 49L, 50L, 52L, 62L, 6L, 8L, 10L, 14L, 16L, 
29L, 40L, 47L, 50L, 52L, 62L, 6L, 8L, 24L, 32L, 39L, 47L, 50L, 
52L, 4L, 32L, 43L, 47L, 50L, 52L, 62L, 4L, 12L, 20L, 47L, 50L, 
52L, 62L, 10L, 20L, 39L, 47L, 48L, 50L, 52L, 62L, 6L, 20L, 35L, 
47L, 50L, 61L, 62L, 8L, 16L, 20L, 32L, 39L, 47L, 50L, 61L, 20L, 
47L, 50L, 52L, 58L, 12L, 14L, 47L, 50L, 12L, 47L, 50L, 52L, 4L, 
7L, 12L, 17L, 47L, 50L, 52L, 56L, 4L, 7L, 12L, 20L, 50L, 52L, 
62L, 7L, 12L, 32L, 50L, 52L, 62L, 7L, 12L, 47L, 50L, 52L, 62L, 
7L, 26L, 32L, 47L, 50L, 52L, 62L, 4L, 7L, 12L, 17L, 39L, 47L, 
50L, 52L, 62L, 4L, 7L, 8L, 32L, 39L, 40L, 47L, 50L, 52L, 62L, 
7L, 12L, 16L, 24L, 39L, 46L, 47L, 48L, 50L, 52L, 62L, 35L, 46L, 
47L, 50L, 52L, 62L, 7L, 24L, 39L, 40L, 46L, 47L, 50L, 52L, 62L, 
7L, 15L, 35L, 50L, 52L, 62L, 7L, 8L, 32L, 35L, 39L, 47L, 50L, 
52L, 53L, 62L, 7L, 14L, 29L, 35L, 42L, 47L, 50L, 52L, 29L, 47L, 
50L, 62L, 24L, 29L, 47L, 50L, 2L, 7L, 12L, 14L, 20L, 40L, 47L, 
51L, 62L, 3L, 9L, 12L, 14L, 24L, 47L, 50L, 62L, 6L, 8L, 9L, 12L, 
14L, 21L, 24L, 33L, 39L, 40L, 44L, 47L, 50L, 52L, 53L, 56L, 61L, 
62L, 6L, 12L, 14L, 40L, 48L, 49L, 62L, 4L, 8L, 32L, 35L, 39L, 
47L, 50L, 52L, 9L, 12L, 26L, 47L, 50L, 52L, 58L, 62L, 4L, 8L, 
20L, 32L, 39L, 40L, 42L, 47L, 48L, 50L, 52L, 53L, 58L, 62L, 4L, 
9L, 24L, 25L, 30L, 32L, 39L, 47L, 50L, 52L, 62L, 4L, 9L, 16L, 
21L, 25L, 26L, 38L, 39L, 41L, 47L, 50L, 51L, 52L, 62L, 4L, 9L, 
16L, 17L, 23L, 25L, 32L, 39L, 40L, 41L, 47L, 50L, 51L, 52L, 62L, 
29L, 40L, 41L, 43L, 47L, 50L, 52L, 53L, 62L, 4L, 5L, 32L, 39L, 
41L, 43L, 47L, 50L, 52L, 53L, 62L, 2L, 9L, 32L, 33L, 39L, 47L, 
50L, 52L, 53L, 62L, 4L, 19L, 24L, 33L, 39L, 47L, 50L, 52L, 53L, 
62L, 2L, 4L, 12L, 14L, 19L, 39L, 47L, 50L, 53L, 2L, 4L, 12L, 
14L, 19L, 33L, 39L, 46L, 50L, 52L, 53L, 61L, 24L, 29L, 39L, 44L, 
47L, 50L, 52L, 53L, 62L, 12L, 13L, 39L, 40L, 47L, 50L, 52L, 6L, 
35L, 47L, 50L, 52L, 4L, 8L, 17L, 20L, 21L, 35L, 50L, 52L, 58L, 
62L, 4L, 8L, 17L, 20L, 32L, 47L, 50L, 52L, 4L, 7L, 16L, 47L, 
50L, 52L, 62L, 4L, 26L, 32L, 47L, 50L, 52L, 62L, 7L, 14L, 32L, 
47L, 50L, 52L, 62L, 12L, 14L, 47L, 48L, 50L, 52L, 7L, 12L, 16L, 
21L, 24L, 39L, 50L, 52L, 58L, 62L, 7L, 12L, 14L, 32L, 47L, 50L, 
52L, 7L, 9L, 14L, 16L, 24L, 47L, 50L, 52L, 62L, 7L, 12L, 24L, 
46L, 47L, 50L, 52L, 62L, 12L, 32L, 47L, 50L, 52L, 62L, 7L, 39L, 
47L, 50L, 52L, 62L, 12L, 24L, 29L, 47L, 50L, 52L, 62L, 7L, 24L, 
47L, 50L, 52L, 62L, 4L, 24L, 29L, 32L, 47L, 48L, 50L, 52L, 62L, 
7L, 47L, 50L, 52L, 62L, 7L, 47L, 50L, 52L, 7L, 32L, 33L, 40L, 
50L, 52L, 58L, 12L, 15L, 20L, 39L, 47L, 50L, 52L, 7L, 12L, 16L, 
32L, 40L, 47L, 50L, 52L, 62L, 7L, 32L, 47L, 50L, 52L, 62L, 7L, 
47L, 50L, 52L, 4L, 7L, 12L, 16L, 24L, 32L, 47L, 50L, 52L, 62L, 
7L, 26L, 47L, 50L, 52L, 4L, 7L, 8L, 16L, 26L, 32L, 47L, 50L, 
52L, 56L, 58L, 62L, 7L, 13L, 32L, 47L, 50L, 52L, 62L, 5L, 7L, 
32L, 43L, 47L, 50L, 52L, 62L, 7L, 26L, 32L, 47L, 50L, 52L, 7L, 
12L, 24L, 32L, 39L, 46L, 47L, 50L, 52L, 7L, 32L, 46L, 47L, 50L, 
52L, 62L, 6L, 12L, 13L, 24L, 33L, 39L, 40L, 43L, 47L, 53L, 54L, 
26L, 43L, 47L, 50L, 51L, 52L, 53L, 8L, 14L, 20L, 29L, 43L, 46L, 
47L, 48L, 50L, 52L, 62L, 8L, 10L, 12L, 21L, 25L, 27L, 39L, 48L, 
50L, 52L, 57L, 4L, 13L, 21L, 24L, 27L, 32L, 39L, 47L, 50L, 52L, 
53L, 4L, 7L, 8L, 20L, 31L, 39L, 50L, 52L, 62L, 12L, 32L, 39L, 
42L, 43L, 47L, 48L, 50L, 52L, 53L, 8L, 15L, 21L, 29L, 39L, 47L, 
50L, 52L, 55L, 4L, 6L, 8L, 21L, 47L, 50L, 52L, 62L, 13L, 33L, 
39L, 47L, 50L, 52L, 62L, 10L, 17L, 36L, 37L, 42L, 47L, 50L, 52L, 
62L, 9L, 44L, 45L, 47L, 50L, 51L, 52L, 62L, 4L, 9L, 10L, 17L, 
21L, 26L, 32L, 39L, 41L, 47L, 50L, 52L, 53L, 62L, 4L, 35L, 47L, 
50L, 52L, 53L, 62L, 8L, 11L, 12L, 24L, 33L, 39L, 40L, 47L, 49L, 
50L, 52L, 53L, 61L, 2L, 7L, 19L, 24L, 33L, 39L, 40L, 47L, 50L, 
51L, 52L, 53L, 62L, 33L, 39L, 47L, 50L, 52L, 53L, 61L, 62L, 4L, 
7L, 8L, 19L, 26L, 32L, 47L, 50L, 52L, 62L, 15L, 19L, 46L, 47L, 
50L, 52L, 53L, 2L, 4L, 18L, 33L, 47L, 50L, 52L, 53L, 4L, 7L, 
19L, 24L, 29L, 35L, 47L, 50L, 52L, 62L, 4L, 15L, 24L, 26L, 32L, 
39L, 40L, 47L, 50L, 51L, 52L, 53L, 7L, 8L, 24L, 29L, 40L, 47L, 
48L, 50L, 52L, 62L, 4L, 12L, 24L, 26L, 29L, 40L, 46L, 47L, 50L, 
52L, 53L, 58L, 62L, 12L, 20L, 24L, 32L, 47L, 50L, 52L, 62L, 4L, 
16L, 39L, 47L, 50L, 52L, 26L, 32L, 39L, 40L, 47L, 48L, 50L, 51L, 
52L, 62L, 7L, 13L, 47L, 50L, 52L, 7L, 8L, 12L, 26L, 32L, 47L, 
50L, 52L, 2L, 7L, 20L, 21L, 33L, 47L, 50L, 52L, 7L, 12L, 20L, 
32L, 47L, 50L, 52L, 62L, 10L, 20L, 39L, 47L, 50L, 52L, 53L, 58L, 
7L, 32L, 47L, 50L, 52L, 62L, 7L, 14L, 17L, 24L, 50L, 52L, 62L, 
4L, 7L, 8L, 12L, 24L, 26L, 46L, 50L, 52L, 62L, 7L, 12L, 16L, 
32L, 39L, 46L, 50L, 52L, 62L, 7L, 19L, 24L, 39L, 50L, 52L, 62L, 
33L, 39L, 47L, 50L, 52L, 58L, 62L, 7L, 12L, 15L, 19L, 47L, 50L, 
51L, 52L, 7L, 23L, 47L, 50L, 51L, 52L, 2L, 4L, 7L, 15L, 16L, 
18L, 19L, 29L, 33L, 37L, 39L, 40L, 44L, 47L, 50L, 52L, 53L, 62L, 
8L, 9L, 12L, 39L, 47L, 50L, 52L, 9L, 12L, 39L, 40L, 47L, 50L, 
52L, 62L, 9L, 12L, 24L, 39L, 47L, 52L, 62L, 6L, 12L, 40L, 47L, 
50L, 52L), .Label = c("albleb", "albodo", "antgha", "apovil", 
"artlak", "briret", "buclan", "cansub", "carsph", "catspa", "cropoi", 
"dalcul", "dallan", "dalnig", "daloli", "dilobo", "dioehr", "diomal", 
"dipint", "diptub", "elltom", "erican", "erysuc", "flesoo", "garcow", 
"garobt", "garsoo", "gmearb", "greeri", "halcor", "holpub", "irvoli", 
"lancor", "lopdup", "mancal", "memedu", "memscu", "milleu", "mitrot", 
"morcor", "ochint", "parama", "pavtom", "permem", "phycol", "phyemb", 
"ptemac", "rotwit", "schole", "shoobt", "shorox", "shosia", "sinsia", 
"stegut", "steneu", "strnux", "symrac", "syz001", "terala", "tercal", 
"terche", "xylxyl"), class = "factor"), occurrence = c(1L, 1L, 
1L, 14L, 1L, 10L, 10L, 1L, 1L, 1L, 4L, 1L, 7L, 3L, 3L, 1L, 1L, 
1L, 1L, 9L, 1L, 1L, 1L, 3L, 5L, 1L, 1L, 1L, 5L, 1L, 1L, 4L, 1L, 
1L, 3L, 4L, 1L, 2L, 1L, 9L, 1L, 2L, 6L, 1L, 1L, 10L, 6L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 1L, 1L, 1L, 3L, 2L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 10L, 21L, 1L, 24L, 5L, 1L, 2L, 3L, 
10L, 10L, 1L, 1L, 2L, 1L, 1L, 1L, 10L, 14L, 31L, 1L, 1L, 1L, 
3L, 1L, 1L, 4L, 1L, 1L, 2L, 4L, 1L, 1L, 2L, 1L, 3L, 2L, 2L, 2L, 
1L, 6L, 13L, 16L, 6L, 1L, 1L, 16L, 3L, 1L, 2L, 3L, 5L, 3L, 2L, 
1L, 28L, 10L, 2L, 1L, 1L, 1L, 1L, 5L, 1L, 1L, 51L, 20L, 1L, 9L, 
5L, 1L, 1L, 3L, 1L, 1L, 1L, 1L, 4L,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"data.frame"
), row.names = c(NA, -1148L), .internal.selfref = <pointer: 0x0000000007b70788>)

1 个答案:

答案 0 :(得分:0)

default = 0作为参数添加到现有代码中:

LoggAbundTGLMSOagg <- tapply(AbundTGLMSOagg$occurrence,list
                      (AbundTGLMSOagg$plot,AbundTGLMSOagg$species),mean, default = 0)

有关详细信息,请参阅?tapply

编辑:或者,将其作为另一种解决方案:How do I replace NA values with zeros in an R dataframe?