2

学校の生徒の成績表データベースを分析しています。私のデータセットは、以下の例と同様に構造化された約 3000 のレコードで構成されています。各観察は、1 人の生徒に対する 1 人の教師の評価です。各観察には、3 文の物語のコメントが含まれています。

私の分析結果を共有するために、コメントから学生の名前の言及を取り除き、他の名前に置き換えたいと思います。理想的な世界では、再現性のために匿名化されたバージョンのデータベースも共有したいと考えています.

学生の名前の一貫性のない使用法 (名 vs ニックネーム vs フルネーム) と学生の名前の構造化されていない使用法は、私のようなアマチュアにとってこれを非常に扱いにくいものにしています。この問題を解決するための私の試みは、コーパス内のドキュメントとしてコメントにアプローチし、使用する関数を作成するtm::removeWordsことでしたが、うまくいきませんでした。前もって感謝します!

サンプルデータ(ここに表のdput)

  Teacher Subject      Student.Name                                                         Comment
1   Black    Math    Richard (Dick) Dick is a terrible student-- why hasn't he been kicked out yet?
2   Black    Math Elizabeth (Betty)                       Betty procrastinates, but does good work.
3   Black    Math   Mary Grace (MG)                      As her teacher, I think MG is my favorite.
4   Brown English    Richard (Dick)                      Richard is terrible at turning in homework.
5   Brown English Elizabeth (Betty)                Elizabeth's work is interfering with her studies.
6   Brown English   Mary Grace (MG)                         Mary Grace should be a teacher someday.
7    Blue    P.E.    Richard (Dick)  Richard (Dick) kicked more field goals than any other student.
8    Blue    P.E. Elizabeth (Betty)    Elizabeth (Betty) needs to work to communicate on the field.
9    Blue    P.E.   Mary Grace (MG)             Mary Grace (MG) needs to stop insulting the teacher

希望するデータ

Teacher Subject Student Name    Comment
Black   Math    A   A is a terrible student-- why hasn't he been kicked out yet?
Black   Math    B   B procrastinates, but does good work.
Black   Math    C   As her teacher, I think C is my favorite.
Brown   English A   A is terrible at turning in homework
Brown   English B   B's work is interfering with her studies.
Brown   English C   C should be a teacher someday.
Blue    P.E.    A   A kicked more field goals than any other student.
Blue    P.E.    B   B needs to work to communicate on the field.
Blue    P.E.    C   C needs to stop insulting the teacher

注意

4か月前、私はこの質問のバージョンを尋ねましたが、返事はありませんでした. 私のソリューションを示すのに役立つと思いましたが、おそらくtmパッケージは広く使用されていません. ということで、もう一枚。

4

2 に答える 2

2

私はパッケージmgsubからここを使用します。qdapこのようなことを行うことができます(ただし、学生が同じIDに属していることを確認してください。これは、各学生のニックネームを含む例に固有すぎる可能性があります):

names <- unique(as.character(reports$Student.Name))
ids <- sample(100000, length(names))

tocheck <- c(
  names, 
  unlist(regmatches(names, gregexpr("(?<=\\().*?(?=\\))", names, perl = T))),
  gsub("\\s*\\([^\\)]+\\)","",as.character(names))
)
reports$Student.Name <- rep(ids, 3)
reports$Comment <- qdap::mgsub(tocheck, rep(ids, 3), reports$Comment)

  Student.Name                                                          Comment
1        61034 61034 is a terrible student-- why hasn't he been kicked out yet?
2        45005                        45005 procrastinates, but does good work.
3        13699                    As her teacher, I think 13699 is my favorite.
4        61034                         61034 is terrible at turning in homework
5        45005                    45005's work is interfering with her studies.
6        13699                               13699 should be a teacher someday.
7        61034            61034 kicked more field goals than any other student.
8        45005                 45005 needs to work to communicate on the field.
9        13699                        13699 needs to stop insulting the teacher
于 2016-09-05T23:00:56.443 に答える