Подмножество данных кадра в список - PullRequest
2 голосов
/ 12 марта 2012

У меня есть фрейм данных, который я хотел бы установить на основе уникальных значений переменной schoolid. Затем они будут занесены в список, поэтому каждый элемент списка является подмножеством фрейма данных. Я, очевидно, знаю, как сделать это для конкретных значений schoolid, по одному, но как я могу делать это систематически, не зная, какие значения могут встречаться в schoolid?

Спасибо за вашу помощь! Джефф

structure(list(schoolid = c(84351L, 84351L, 84351L, 84351L, 84351L, 
84351L, 84351L, 84351L, 84351L, 84351L, 84351L, 84351L, 84351L, 
84351L, 84351L, 84384L, 84384L, 84384L, 84384L, 84384L, 84384L, 
84384L, 84384L, 84384L, 84384L, 84384L, 84384L, 84384L, 84384L, 
84384L, 84385L, 84385L, 84385L, 84385L, 84385L, 84385L, 84385L, 
84385L, 84385L, 84385L, 84385L, 84385L, 84385L, 84385L, 84385L, 
84386L, 84386L, 84386L, 84386L, 84386L, 84386L, 84386L, 84386L, 
84386L, 84386L, 84386L, 84386L, 84386L, 84386L, 84386L, 84387L, 
84387L, 84387L, 84387L, 84387L, 84387L, 84387L, 84387L, 84387L, 
84388L, 84388L, 84388L, 84388L, 84388L, 84388L, 84388L, 84388L, 
84388L, 84389L, 84389L, 84389L, 84389L, 84389L, 84389L, 84389L, 
84389L, 84389L, 84395L, 84395L, 84395L, 84395L, 84395L, 84395L, 
84397L, 84397L, 84397L, 84397L, 84397L, 84397L, 84398L, 84398L, 
84398L, 84398L, 84398L, 84398L, 84351L, 84351L, 84351L, 84351L, 
84351L, 84351L, 84351L, 84351L, 84351L, 84351L, 84351L, 84351L, 
84384L, 84384L, 84384L, 84384L, 84384L, 84384L, 84384L, 84384L, 
84384L, 84384L, 84384L, 84385L, 84385L, 84385L, 84385L, 84385L, 
84385L, 84385L, 84385L, 84385L, 84385L, 84385L, 84385L, 84385L, 
84386L, 84386L, 84386L, 84386L, 84386L, 84386L, 84386L, 84386L, 
84386L, 84386L, 84386L, 84386L, 84387L, 84387L, 84387L, 84387L, 
84387L, 84387L, 84387L, 84387L, 84388L, 84388L, 84388L, 84388L, 
84388L, 84388L, 84389L, 84389L, 84389L, 84389L, 84389L, 84389L, 
84389L, 84389L, 84389L, 84397L, 84397L, 84398L, 84398L, 84398L, 
84398L, 84398L, 84351L, 84351L, 84351L, 84351L, 84351L, 84351L, 
84351L, 84351L, 84351L, 84351L, 84351L, 84351L, 84351L, 84351L, 
84384L, 84384L, 84384L, 84384L, 84384L, 84384L, 84384L, 84384L, 
84384L, 84384L, 84384L, 84384L, 84384L, 84385L, 84385L, 84385L, 
84385L, 84385L, 84385L, 84385L, 84385L, 84385L, 84385L, 84385L, 
84385L, 84385L, 84385L, 84385L, 84386L, 84386L, 84386L, 84386L, 
84386L, 84386L, 84386L, 84386L, 84386L, 84386L, 84386L, 84386L, 
84386L, 84386L, 84387L, 84387L, 84387L, 84387L, 84387L, 84387L, 
84387L, 84387L, 84388L, 84388L, 84388L, 84388L, 84388L, 84388L, 
84388L, 84388L, 84388L, 84389L, 84389L, 84389L, 84389L, 84389L, 
84389L, 84389L, 84395L, 84395L, 84395L, 84395L, 84397L, 84397L, 
84397L, 84397L, 84397L, 84397L, 84398L, 84398L, 84398L, 84398L, 
84398L, 84398L), subgroup = c("All", "All", "All", "All", "All", 
"All", "All", "All", "All", "All", "All", "All", "All", "All", 
"All", "All", "All", "All", "All", "All", "All", "All", "All", 
"All", "All", "All", "All", "All", "All", "All", "All", "All", 
"All", "All", "All", "All", "All", "All", "All", "All", "All", 
"All", "All", "All", "All", "All", "All", "All", "All", "All", 
"All", "All", "All", "All", "All", "All", "All", "All", "All", 
"All", "All", "All", "All", "All", "All", "All", "All", "All", 
"All", "All", "All", "All", "All", "All", "All", "All", "All", 
"All", "All", "All", "All", "All", "All", "All", "All", "All", 
"All", "All", "All", "All", "All", "All", "All", "All", "All", 
"All", "All", "All", "All", "All", "All", "All", "All", "All", 
"All", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", 
"ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", 
"ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", 
"ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", 
"ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", 
"ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", 
"ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", 
"ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", 
"ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "ELL", "SpEd", "SpEd", 
"SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", 
"SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", 
"SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", 
"SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", 
"SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", 
"SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", 
"SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", 
"SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", 
"SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", 
"SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", 
"SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd", 
"SpEd", "SpEd", "SpEd", "SpEd", "SpEd", "SpEd"), grade = c(0L, 
0L, 0L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 0L, 0L, 
0L, 1L, 1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 2L, 3L, 
1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 3L, 1L, 2L, 3L, 
1L, 2L, 3L, 1L, 2L, 1L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 
1L, 2L, 3L), .Label = c("AGL", "BGL", "OGL"), class = "factor"), 
    num = c(54L, 9L, 32L, 58L, 15L, 45L, 76L, 22L, 81L, 83L, 
    1L, 49L, 71L, 22L, 19L, 51L, 34L, 37L, 86L, 10L, 44L, 41L, 
    24L, 79L, 55L, 20L, 60L, 52L, 11L, 7L, 59L, 21L, 13L, 89L, 
    34L, 23L, 68L, 21L, 66L, 70L, 12L, 50L, 51L, 6L, 8L, 51L, 
    5L, 27L, 45L, 23L, 13L, 31L, 12L, 44L, 31L, 7L, 47L, 31L, 
    17L, 8L, 36L, 9L, 13L, 36L, 17L, 23L, 45L, 16L, 42L, 32L, 
    7L, 17L, 49L, 16L, 19L, 54L, 5L, 44L, 18L, 10L, 24L, 49L, 
    17L, 19L, 73L, 7L, 28L, 42L, 5L, 2L, 32L, 1L, 7L, 41L, 14L, 
    20L, 34L, 22L, 29L, 64L, 17L, 25L, 26L, 11L, 18L, 6L, 4L, 
    4L, 2L, 2L, 2L, 1L, 4L, 1L, 4L, 2L, 4L, 1L, 6L, 4L, 5L, 7L, 
    1L, 2L, 8L, 2L, 2L, 1L, 7L, 5L, 2L, 5L, 1L, 3L, 2L, 4L, 5L, 
    2L, 4L, 1L, 1L, 3L, 2L, 2L, 3L, 4L, 3L, 1L, 1L, 7L, 1L, 3L, 
    1L, 3L, 2L, 2L, 3L, 6L, 3L, 2L, 3L, 1L, 1L, 2L, 1L, 1L, 2L, 
    1L, 4L, 7L, 3L, 6L, 4L, 1L, 2L, 3L, 1L, 3L, 2L, 6L, 3L, 2L, 
    2L, 7L, 2L, 2L, 11L, 7L, 6L, 6L, 7L, 20L, 13L, 10L, 9L, 11L, 
    4L, 2L, 4L, 3L, 5L, 2L, 7L, 6L, 12L, 3L, 11L, 10L, 3L, 3L, 
    7L, 5L, 2L, 7L, 12L, 3L, 13L, 6L, 12L, 6L, 5L, 7L, 1L, 1L, 
    2L, 4L, 1L, 2L, 8L, 11L, 3L, 5L, 5L, 9L, 2L, 2L, 10L, 2L, 
    2L, 1L, 3L, 5L, 6L, 2L, 1L, 7L, 11L, 2L, 3L, 2L, 4L, 8L, 
    3L, 2L, 2L, 8L, 1L, 6L, 7L, 4L, 3L, 2L, 2L, 3L, 2L, 2L, 1L, 
    5L, 3L, 4L, 2L, 7L, 5L, 7L, 7L, 4L, 1L, 5L, 1L)), .Names = c("schoolid", 
"subgroup", "grade", "FnPLevel", "num"), row.names = c(NA, 279L
), class = "data.frame")

Ответы [ 2 ]

6 голосов
/ 12 марта 2012

Просто используйте split:

schoolid_groups <- split(Data, Data$schoolid)
2 голосов
/ 12 марта 2012

взгляните на dlply из пакета plyr (d = вход df, l = вывод списка, ply = применить)

library(plyr) 

df <- data.frame(a=letters, b=rnorm(260))

out <- dlply(df, .(a))

str(out)
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...