2012-03-12 12 views
1

私は、schoolid変数の一意の値に基づいてサブセット化したいデータフレームを持っています。これらはリストにスコアリングされるので、リストの各メンバーはデータフレームのサブセットです。私は明らかに、一度に1つの特定の学校の値に対してこれを行う方法を知っていますが、どの値が学校で発生する可能性があるかを知らずにこれを体系的に行うことはできますか?サブセットデータフレームをリストに入れる

ありがとうございました! ジェフは

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, 1L, 1L,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L, 
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") 
+0

私はあなたの質問を完全に理解していませんが、 'subset'を使って' split'や 'lapply'が役に立つかもしれません。私はあなたが分割すると予想されるものをもう少し明確にしなければならないかもしれないと思います。範囲が必要ですか?ある値。私は 'match'や' gregexpr'が解決策の一部かもしれないと思います。 –

答えて

6

だけ使用split

schoolid_groups <- split(Data, Data$schoolid) 
2

plyrパッケージからdlplyを見てみましょう(d = DF入力、l =リスト出力、ply =適用されます)

library(plyr) 

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

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

str(out) 
関連する問題