我想对A列中两个数字之间的每个数字集进行计数(因此先计算1的数量,然后计算2的数量,依此类推)。本质上,我正在尝试做的(尽管我知道这是错误的):
substrate_types <- c("Medium sands",
"Tidal flat mixed sediments",
"Muddy sand",
"Mud",
"*.Are (fine and very fine sands/sparse infauna)",
"Fine and very fine sands; Arenicola beds/sparse infauna",
"Gravelly sands",
"Rock",
"Scoured cobbles w. diverse encrusting & low faunal turf fauna")
sub_type_rectx <- c(-4.15, -3.95)
sub_type_recty <- c(57.81, 57.88)
sub_type_colours <- c("blue",
"blue",
"red",
"purple",
"orange",
"black",
"red",
"darkred",
"darkblue")
plt_sub_type <- ggplot(data = uk, colour = colours) +
geom_sf(fill = fill_colour, colour = line_colour) +
geom_sf(data = intertidal, colour = "black", fill = "wheat3")+
#geom_sf(data = scot, colour = line_colour, fill = fill_colour) +
geom_sf(data = biotope_list_sf[["Medium sands"]], aes(colour = "blue"), fill = "lightblue", alpha = 0.5) +
geom_sf(data = biotope_list_sf[["Tidal flat mixed sediments"]], aes(colour = "blue"), fill = "lightblue", alpha = 0.5) +
geom_sf(data = biotope_list_sf[["Muddy sand"]], aes(colour = "red"), fill = "pink", alpha = 0.5) +
geom_sf(data = biotope_list_sf[["Mud"]], aes(colour = "purple1"), fill = "purple", alpha = 0.5) + # hard substrate, Possibly contains mussels
geom_sf(data = biotope_list_sf[["*.Are (fine and very fine sands/sparse infauna)"]], aes(colour = "orange"), fill = "orange", alpha = 0.5) +
geom_sf(data = biotope_list_sf[["Fine and very fine sands; Arenicola beds/sparse infauna"]], aes(colour = "green"), fill = "black", alpha = 0.5) +
geom_sf(data = biotope_list_sf[["Gravelly sands"]], aes(colour = "purple1"), fill = "purple", alpha = 0.5) + # hard substrate, Possibly contains mussels
geom_sf(data = biotope_list_sf[["Rock"]], aes(colour = "orange"), fill = "orange", alpha = 0.5) +
geom_sf(data = biotope_list_sf[["Scoured cobbles w. diverse encrusting & low faunal turf fauna"]], aes(colour = "green"), fill = "black", alpha = 0.5) +
geom_sf(data = A9, colour = road_colour) +
geom_sf(data = bridge, colour = "black", fill = "black", alpha = 0.8) +
# Crop and scales
coord_sf(xlim = sub_type_rectx, ylim = sub_type_recty, expand = FALSE) +
scale_x_continuous(breaks = seq(sub_type_rectx[1], sub_type_rectx[2], by = 0.1), labels = label_function_x) +
scale_y_continuous(breaks = seq(sub_type_recty[1], sub_type_recty[2], by = 0.03), labels = label_function_y) +
#scale_colour_identity(name = 'Legend', guide = 'legend',labels = mytilus) +
scale_colour_manual(values = sub_type_colours, labels = substrate_types, drop = FALSE) +
# Annotations
annotation_scale(location = "tr",
width_hint = 0.3) +
annotation_north_arrow(location = "tr",
which_north = "true",
pad_x = unit(0.1, "in"),
pad_y = unit(0.2, "in"),
style = north_arrow_fancy_orienteering) +
# Styling
theme(panel.background = element_rect("white", "black", 1)) +
theme(axis.title = element_blank()) +
geom_rect(xmin = sub_type_rectx[1],
xmax = sub_type_rectx[2],
ymin = sub_type_recty[1],
ymax = sub_type_recty[2], fill = NA, colour = "black", size = 1)
plt_sub_type #Show plot
主要是我需要帮助的循环。我不知道如何在两个数字之间循环?除非我做错了?
答案 0 :(得分:0)
您正在尝试在For...Next
循环中使用For Each...Next
循环的功能。尽管非常相似,但第一个将遍历一个数字范围,而第二个将遍历一个数组或集合。
尝试:
For rangeNo = 1 to top
countNo = Application.WorksheetFunction.CountIf(Range(Cells(2, 1), Cells(lastRow, 1)), rangeNo)
msgbox (countNo)
Next
注意,您不需要递增rangeNo
-在循环中分配它的值时,您也不需要在代码中更早地这样做。