例如:
df <- structure(list(Census_Year = c(2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2011L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L, 2016L), County.and.City = c("Carlow", "Cavan", "Clare", "Cork City", "Cork County", "Dún Laoghaire-Rathdown", "Donegal", "Dublin City", "Fingal", "Galway City", "Galway County", "Kerry", "Kildare", "Kilkenny", "Laois", "Leitrim", "Limerick City and County", "Longford", "Louth", "Mayo", "Meath", "Monaghan", "Offaly", "Roscommon", "Sligo", "South Dublin", "Tipperary", "Waterford City and County", "Westmeath", "Wexford", "Wicklow", "Carlow", "Cavan", "Clare", "Cork City", "Cork County", "Dún Laoghaire-Rathdown", "Donegal", "Dublin City", "Fingal", "Galway City", "Galway County", "Kerry", "Kildare", "Kilkenny", "Laois", "Leitrim", "Limerick City and County", "Longford", "Louth", "Mayo", "Meath", "Monaghan", "Offaly", "Roscommon", "Sligo", "South Dublin", "Tipperary", "Waterford City and County", "Westmeath", "Wexford", "Wicklow"), Total = c(5908L, 7331L, 10542L, 12266L, 28603L, 11071L, 18869L, 51699L, 22640L, 7234L, 15311L, 13519L, 18639L, 8992L, 8260L, 3047L, 18537L, 4562L, 13792L, 11866L, 16292L, 5982L, 8313L, 5856L, 5624L, 26039L, 14996L, 11572L, 8637L, 16170L, 12674L, 4507L, 5413L, 7018L, 8943L, 18287L, 7716L, 12829L, 39200L, 15415L, 5175L, 9938L, 8701L, 12297L, 6044L, 6068L, 2163L, 12935L, 3701L, 10058L, 8591L, 10523L, 3831L, 5744L, 3847L, 4250L, 18265L, 10867L, 8323L, 6666L, 11478L, 8603L)), row.names = c(NA, -62L), groups = structure(list(Census_Year = c(2011L, 2016L), .rows = structure(list(1:31, 32:62), ptype = integer(0), class = c("vctrs_list_of", "vctrs_vctr", "list"))), row.names = 1:2, class = c("tbl_df", "tbl", "data.frame"), .drop = TRUE), class = c("grouped_df", "tbl_df", "tbl", "data.frame"))
i <- grepl( "Dublin|Dun Laoghaire Rathdown", df$County.and.City )
df$County.and.City[ i ] <- "Dublin"
df %<>% group_by( Census_Year, County.and.City ) %>%
summarize( Total = sum(Total) )
print.data.frame(df)
你没有这么说,但我想你的意思是把这三个区的总数加到都柏林的总数?
输出:
Census_Year County.and.City Total
1 2011 Carlow 5908
2 2011 Cavan 7331
3 2011 Clare 10542
4 2011 Cork City 12266
5 2011 Cork County 28603
6 2011 Dún Laoghaire-Rathdown 11071
7 2011 Donegal 18869
8 2011 Dublin 77738
9 2011 Fingal 22640
10 2011 Galway City 7234
11 2011 Galway County 15311
12 2011 Kerry 13519
13 2011 Kildare 18639
14 2011 Kilkenny 8992
15 2011 Laois 8260
16 2011 Leitrim 3047
17 2011 Limerick City and County 18537
18 2011 Longford 4562
19 2011 Louth 13792
20 2011 Mayo 11866
21 2011 Meath 16292
22 2011 Monaghan 5982
23 2011 Offaly 8313
24 2011 Roscommon 5856
25 2011 Sligo 5624
26 2011 Tipperary 14996
27 2011 Waterford City and County 11572
28 2011 Westmeath 8637
29 2011 Wexford 16170
30 2011 Wicklow 12674
31 2016 Carlow 4507
32 2016 Cavan 5413
33 2016 Clare 7018
34 2016 Cork City 8943
35 2016 Cork County 18287
36 2016 Dún Laoghaire-Rathdown 7716
37 2016 Donegal 12829
38 2016 Dublin 57465
39 2016 Fingal 15415
40 2016 Galway City 5175
41 2016 Galway County 9938
42 2016 Kerry 8701
43 2016 Kildare 12297
44 2016 Kilkenny 6044
45 2016 Laois 6068
46 2016 Leitrim 2163
47 2016 Limerick City and County 12935
48 2016 Longford 3701
49 2016 Louth 10058
50 2016 Mayo 8591
51 2016 Meath 10523
52 2016 Monaghan 3831
53 2016 Offaly 5744
54 2016 Roscommon 3847
55 2016 Sligo 4250
56 2016 Tipperary 10867
57 2016 Waterford City and County 8323
58 2016 Westmeath 6666
59 2016 Wexford 11478
60 2016 Wicklow 8603
问题内容: 我在Javascript中有一组全局计数器变量: 等等 然后,我有了一个Javascript函数,该函数接受一个映射到这些全局计数器的“索引”数字。在此函数内部,我需要使用传递给该函数的“索引”值来读写这些全局计数器。 我希望它如何工作的示例,但当然根本不起作用: 我希望我要实现的目标是明确的。如果没有,我会尽力澄清。谢谢。 编辑说明: 我不是要增加计数器的名称,而是要增加计数器包含的
可能重复: Java中的动态变量名: 假设我有一个字符串,如下所示。 现在,我想创建一个字符串,但是字符串的变量将被称为“Hello”。为了使字符串名为“Hello”,我必须访问string以获取名称“Hello”,这样我就可以将其用作变量名。下面是我想看的。 感谢您的努力,请尝试向我解释,因为我是Java初学者D
我正在尝试创建一个新变量,该变量仅在满足特定条件时才打印一系列列的第一个值。 为了澄清,我的数据库看起来像这样: 我想创建一个变量(main),仅当值不是以C00到C99开头时,才打印第一个var列中的值。如果值确实以该条件开头,那么我想在下一列测试该条件,直到满足条件并打印该值。 因此,对于上表,新创建的变量(main)应如下所示: 我不太确定从哪里开始,但我怀疑这可能涉及突变()和ifelse
我想做的是在一个对象中保留一个用户数据库,这样我就可以给每个用户赋值,但是我找不到一种方法来实现。 我试过只执行和,但这只写入未定义的内容。如有任何建议将不胜感激。
当你使用了一个未知的变量名,通常 JavaScript 会自动创建全局变量: function f() { foo = 123 } f() foo 123 好在你会在 ECMAScript5 的严谨模式得到警告[1]: function f() { 'use strict'; foo = 123 } f() ReferenceError: foo is not defined 参考 [1] Jav
我有很多海面温度NetCDF文件,具有相同的纬度和纬度,但时间变量不同。我想尝试通过组合时间变量将其组合成一个NetCDF文件,因为每个NetCDF文件中的时间变量是连续的 有没有更有效的方法?因为在CDO(气候数据操作员)中,我无法进行循环 下面是我使用的文件名的一个例子 带模式sstdas_(年)(月)(dekad)