A reprex
provided in the previous question contains the data
d <- data.frame(pais = c(
10L, 15L, 15L, 10L, 15L, 15L, 15L, 15L,
10L, 15L, 15L, 15L, 15L, 15L, 10L, 10L, 10L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 15L
), ccaa = c(
16L, 13L, 13L, 13L, 13L, 7L, 9L, 12L,
17L, 9L, 13L, 9L, 9L, 7L, 9L, 9L, 9L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 9L
), gastototal = c(
2104.8327842, 3339.4242179, 2527.0036036,
1076.4172965, 2812.0859804, 6686.339234, 2196.4232084, 6941.6912321,
2085.3796211, 3355.3558589, 3422.6737527, 2697.8463611, 1750.2838905,
4599.6563689, 1444.3916741, 1403.0404296, 1345.220257, 1303.2814619,
704.5863107, 1345.4311241, 1495.1874334, 1074.8804203, 1345.4311241,
1252.3900093, 997.72492846))
It appears that the objective is to subset the data by the pais
variable, and from the screenshot the failure is arising from using the name table
for the object. Because table
is the name of a built-in function it cannot be subset and throws an error
object of type 'closure' is not subsettable
Using d
, however, allows the subset to proceed by asking, in effect
- How many unique values of
pais
occur in the data frame?
- In which rows of the data frame do they occur?
d <- data.frame(pais = c(
10L, 15L, 15L, 10L, 15L, 15L, 15L, 15L,
10L, 15L, 15L, 15L, 15L, 15L, 10L, 10L, 10L, 6L, 6L, 6L, 6L,
6L, 6L, 6L, 15L
), ccaa = c(
16L, 13L, 13L, 13L, 13L, 7L, 9L, 12L,
17L, 9L, 13L, 9L, 9L, 7L, 9L, 9L, 9L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 9L
), gastototal = c(
2104.8327842, 3339.4242179, 2527.0036036,
1076.4172965, 2812.0859804, 6686.339234, 2196.4232084, 6941.6912321,
2085.3796211, 3355.3558589, 3422.6737527, 2697.8463611, 1750.2838905,
4599.6563689, 1444.3916741, 1403.0404296, 1345.220257, 1303.2814619,
704.5863107, 1345.4311241, 1495.1874334, 1074.8804203, 1345.4311241,
1252.3900093, 997.72492846))
unique(d$pais)
#> [1] 10 15 6
p6 <- which(d$pais == 6)
p10 <- which(d$pais == 10)
p15 <- which(d$pais == 15)
d[p6,]
#> pais ccaa gastototal
#> 18 6 4 1303.2815
#> 19 6 4 704.5863
#> 20 6 4 1345.4311
#> 21 6 4 1495.1874
#> 22 6 4 1074.8804
#> 23 6 4 1345.4311
#> 24 6 4 1252.3900
d[p10,]
#> pais ccaa gastototal
#> 1 10 16 2104.833
#> 4 10 13 1076.417
#> 9 10 17 2085.380
#> 15 10 9 1444.392
#> 16 10 9 1403.040
#> 17 10 9 1345.220
d[p15,]
#> pais ccaa gastototal
#> 2 15 13 3339.4242
#> 3 15 13 2527.0036
#> 5 15 13 2812.0860
#> 6 15 7 6686.3392
#> 7 15 9 2196.4232
#> 8 15 12 6941.6912
#> 10 15 9 3355.3559
#> 11 15 13 3422.6738
#> 12 15 9 2697.8464
#> 13 15 9 1750.2839
#> 14 15 7 4599.6564
#> 25 15 9 997.7249