Error on variable length

Dear All,

I want to create ranks for for group id's( tabletsharing$Groupid), who are using the same devices ( WifiMac) based on which usage cluster these groups belong. I have marked these clusters as 1,2,3 and 4.

TabletSharing <-
TabletSharing %>%
group_by(WifiMac) %>%
group_by(TabletSharing$Group Clusters) %>%
mutate(my_ranks1 = order(order(TabletSharing$GroupID, decreasing=TRUE)))

When I run this code, I am getting this error:

Error: Column TabletSharing$Group Clusters`` must be length 2 (the group size) or one, not 812

I can't understand this error, please help and a way to get around it this.

TIA.

We don't really have enough info to help you out, since we don't now the structure of your data and your desired output, could you ask this with a minimal REPRoducible EXample (reprex)? A reprex makes it much easier for others to understand your issue and figure out how to help.

1 Like

@andresrcs

Sharing the piece of data with the desired column.

https://docs.google.com/spreadsheets/d/1rIZDJTGbwwZYhLStEBsc-IugzGw3_FLxQZhpKnG-iD8/edit#gid=0

Best,

Your spreadsheet is private so we don't have access to it, please share sample data in the way is explained in the link I gave you before.

Done, now you can view the sample data.

I don't think group_by(TabletSharing$Group Clusters) this variable (Group Clusters) is in the test data. Can you describe what you think the code in your mutate is doing?

library(dplyr)

testdat <- tibble::tribble(
  ~Auto.ID,            ~WifiMac, ~GroupID.x, ~VillageId, ~Duplicate, ~`Duplicate.(groups)`, ~Desirable.Result,
        1L, "48:88:ca:4f:74:37", "GRP18450",      1403L,      "Low",                    1L,                0L,
        2L, "48:88:ca:4f:74:37", "GRP18457",      1403L,      "Low",                    1L,                0L,
        4L, "48:88:ca:4f:a6:a4", "GRP12782",       752L,      "Low",                    1L,                2L,
        3L, "48:88:ca:4f:a6:a4", "GRP12795",       752L,   "Medium",                    2L,                1L,
        5L, "48:88:ca:4f:a6:ef", "GRP12788",       752L,      "Low",                    1L,                2L,
        6L, "48:88:ca:4f:a6:ef", "GRP12789",       752L,   "Medium",                    2L,                1L,
        7L, "48:88:ca:4f:a7:00", "GRP12698",       757L,     "Best",                    4L,                1L,
        8L, "48:88:ca:4f:a7:00", "GRP12689",       757L,     "High",                    3L,                2L
  )

testdat %>%
  group_by(WifiMac, `Duplicate.(groups)`) %>%
  mutate("my_ranks1" = order(order("GroupID.x", decreasing = TRUE)))
#> # A tibble: 8 x 8
#> # Groups:   WifiMac, Duplicate.(groups) [7]
#>   Auto.ID WifiMac GroupID.x VillageId Duplicate `Duplicate.(gro…
#>     <int> <chr>   <chr>         <int> <chr>                <int>
#> 1       1 48:88:… GRP18450       1403 Low                      1
#> 2       2 48:88:… GRP18457       1403 Low                      1
#> 3       4 48:88:… GRP12782        752 Low                      1
#> 4       3 48:88:… GRP12795        752 Medium                   2
#> 5       5 48:88:… GRP12788        752 Low                      1
#> 6       6 48:88:… GRP12789        752 Medium                   2
#> 7       7 48:88:… GRP12698        757 Best                     4
#> 8       8 48:88:… GRP12689        757 High                     3
#> # … with 2 more variables: Desirable.Result <int>, my_ranks1 <int>

Created on 2019-02-26 by the reprex package (v0.2.1)

Column duplicate groups is the column Group Clusters, sorry for the confusion. I have the changed the name accordingly. Do have a look at it again.

I'm still confused by what exactly you're looking for. Because you've grouped by two variables, the grouping for the second will occur within the grouping for the first (which is why you see the order-swap for some of your desired output, since the WifiMac variables are different:

library(dplyr)

testdat <- tibble::tribble(
  ~Auto.ID,            ~WifiMac, ~GroupID.x, ~VillageId, ~Duplicate, ~`Duplicate.(groups)`, ~Desirable.Result,
  1L, "48:88:ca:4f:74:37", "GRP18450",      1403L,      "Low",                    1L,                0L,
  2L, "48:88:ca:4f:74:37", "GRP18457",      1403L,      "Low",                    1L,                0L,
  4L, "48:88:ca:4f:a6:a4", "GRP12782",       752L,      "Low",                    1L,                2L,
  3L, "48:88:ca:4f:a6:a4", "GRP12795",       752L,   "Medium",                    2L,                1L,
  5L, "48:88:ca:4f:a6:ef", "GRP12788",       752L,      "Low",                    1L,                2L,
  6L, "48:88:ca:4f:a6:ef", "GRP12789",       752L,   "Medium",                    2L,                1L,
  7L, "48:88:ca:4f:a7:00", "GRP12698",       757L,     "Best",                    4L,                1L,
  8L, "48:88:ca:4f:a7:00", "GRP12689",       757L,     "High",                    3L,                2L
)

testdat %>%
  group_by(WifiMac, `Duplicate.(groups)`) %>%
  arrange(desc(GroupID.x))
#> # A tibble: 8 x 7
#> # Groups:   WifiMac, Duplicate.(groups) [7]
#>   Auto.ID WifiMac GroupID.x VillageId Duplicate `Duplicate.(gro…
#>     <int> <chr>   <chr>         <int> <chr>                <int>
#> 1       2 48:88:… GRP18457       1403 Low                      1
#> 2       1 48:88:… GRP18450       1403 Low                      1
#> 3       3 48:88:… GRP12795        752 Medium                   2
#> 4       6 48:88:… GRP12789        752 Medium                   2
#> 5       5 48:88:… GRP12788        752 Low                      1
#> 6       4 48:88:… GRP12782        752 Low                      1
#> 7       7 48:88:… GRP12698        757 Best                     4
#> 8       8 48:88:… GRP12689        757 High                     3
#> # … with 1 more variable: Desirable.Result <int>

testdat %>%
  group_by(WifiMac) %>%
  group_by(`Duplicate.(groups)`) %>%
  arrange(desc(GroupID.x))
#> # A tibble: 8 x 7
#> # Groups:   Duplicate.(groups) [4]
#>   Auto.ID WifiMac GroupID.x VillageId Duplicate `Duplicate.(gro…
#>     <int> <chr>   <chr>         <int> <chr>                <int>
#> 1       2 48:88:… GRP18457       1403 Low                      1
#> 2       1 48:88:… GRP18450       1403 Low                      1
#> 3       3 48:88:… GRP12795        752 Medium                   2
#> 4       6 48:88:… GRP12789        752 Medium                   2
#> 5       5 48:88:… GRP12788        752 Low                      1
#> 6       4 48:88:… GRP12782        752 Low                      1
#> 7       7 48:88:… GRP12698        757 Best                     4
#> 8       8 48:88:… GRP12689        757 High                     3
#> # … with 1 more variable: Desirable.Result <int>

Created on 2019-02-26 by the reprex package (v0.2.1)

@mara

Each Wifi mac has two group id's associated with it. And I want to rank these groups for each wifi mac based on their usage cluster.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.