Week 4 NICER、データのフォーマット、文字列の検索

Masato Terai

作成日:2022/11/4 最終更新: 2022-11-04 14:42:01

授業のメモ

box <- c(1:10)

box_2 <- c(11:20)

# show all variables
ls()
## [1] "box"   "box_2"
# remove variables
rm(box)

[Ctr] + [Alt] +[I] => チャンク作成

setwd("C:/Users/mtera/Documents/sugiura_r_2022/2020-11-24NICER1_3_2/NICER_NNS/")

jpn501 <- readLines("JPN501.txt") #1行ずつファイルを読み込む
## Warning in readLines("JPN501.txt"): 'JPN501.txt' で不完全な最終行が見つかりまし
## た

課題 1

“課題です。学習者のデータと母語話者のデータそれぞれ10ファイルずつ、読み込んでください。”

母語話者

setwd("C:/Users/mtera/Documents/sugiura_r_2022/2020-11-24NICER1_3_2/NICER_NS/")
NSs <- list()
file <- list.files(path = "C:/Users/mtera/Documents/sugiura_r_2022/2020-11-24NICER1_3_2/NICER_NS")
for (i in 1:10){
  abox <- readLines(file[i])
  NSs[[i]] <- abox 
}

データの数

head(length(NSs))
## [1] 10

学習者

setwd("C:/Users/mtera/Documents/sugiura_r_2022/2020-11-24NICER1_3_2/NICER_NNS/")
NNSs <- list()
file <- list.files(path = "C:/Users/mtera/Documents/sugiura_r_2022/2020-11-24NICER1_3_2/NICER_NNS")
for (i in 1:10){
  abox <- readLines(file[i])
  NNSs[[i]] <- abox 
}
## Warning in readLines(file[i]): 'JPN501.txt' で不完全な最終行が見つかりました
## Warning in readLines(file[i]): 'JPN503.txt' で不完全な最終行が見つかりました
## Warning in readLines(file[i]): 'JPN504.txt' で不完全な最終行が見つかりました
## Warning in readLines(file[i]): 'JPN505.txt' で不完全な最終行が見つかりました
## Warning in readLines(file[i]): 'JPN506.txt' で不完全な最終行が見つかりました
## Warning in readLines(file[i]): 'JPN507.txt' で不完全な最終行が見つかりました
## Warning in readLines(file[i]): 'JPN508.txt' で不完全な最終行が見つかりました
## Warning in readLines(file[i]): 'JPN509.txt' で不完全な最終行が見つかりました
## Warning in readLines(file[i]): 'JPN510.txt' で不完全な最終行が見つかりました

データの数

length(NNSs)
## [1] 10

文字列の検索

However

母語話者

for(f in 1:length(NSs)){
  result <- grep("However", NSs[[f]])
  print(result)
}
## [1] 45 54 84
## [1] 30
## [1] 34
## [1] 75
## [1] 56 83
## integer(0)
## [1] 30 50
## [1] 31 60 78
## [1]  36 113 122 132
## [1] 63

使用例

for(f in 1:length(NSs)){
  result <- grep("however", NSs[[f]], value=T, ignore.case=T)
  print(result)
}
## [1] "*NS501:\tHowever in the French educational system instead of a head or a body there is a thesis and an anti-thesis or point and counter point in which the writer must oppose his or her original statements."
## [2] "*NS501:\tThis makes the facts easy to access, however, it does not force the writer to challenge his or her own logic in the process, leaving the ideas themselves rigid."                                    
## [3] "*NS501:\tHowever what the French lose in logical flow they gain in critical thinking."                                                                                                                        
## [4] "*NS501:\tHowever, sadly with the continuous failings of the American educational system, these lofty dreams yet remain dreams for a generation of potential Newtons and Einsteins."                           
## [1] "*NS502:\tHowever, with growing competition in workplaces and with newer jobs being developed on a regular basis, it may be necessary to reexamine this two-dimensional hierarchy in order to better prepare students for the changing world."
## [1] "*NS503:\tHowever, I worry that in today's increasingly global society, in which scientific developments are often explicitly prioritized over humanities-based education and research around the world, our global society is perhaps sacrificing crucial analysis of the potential consequences of such scientific research."
## [2] "*NS503:\tHumanities-based education and analysis, however, has the potential to challenge such ideology and, thereby, transform contemporary global society for the better."                                                                                                                                                  
## [1] "*NS504:\tHowever, both systems are not completely different, as they both take into account the importance of academic achievement and also the base of the curriculum, albeit having its differences, remains based on a language, social science, natural science and mathematics core."
## [1] "*NS505:\tHowever Australians have sought to distinguish themselves from the Brits by assuming the role of the scrapper, the underdog."
## [2] "*NS505:\tHowever, there are also some negative aspects to Australia's sporting identity."                                             
## [3] "*NS505:\tAustralia presents itself to the world as a sporting nation, however I challenge the validity of this representation."       
## character(0)
## [1] "*NS507:\tHowever, the situation in the United States is much different with most children beginning their first foreign language classes only in high school, if at all."
## [2] "*NS507:\tHowever, a similar attitude is displayed when an American finds themselves abroad: Why can't they just speak English?"                                          
## [1] "*NS508:\tHowever, as English began to increase in popularity worldwide its influence also took hold of Scotland."                                                                                                                                       
## [2] "*NS508:\tHowever, even thought the education method is quite successful the lack of interest and importance on Gaelic means the number of students attending these schools are limited and Gaelic is not being used in the world outside the classroom."
## [3] "*NS508:\tHowever, that is most certainly easier said than done."                                                                                                                                                                                        
## [1] "*NS509:\tHowever, today paper money is made of the same materials and the only thing that distinguishes one bill from another is the digit printed on each one."
## [2] "*NS509:\tHowever, I think that people need to reassess what is important to them at what is valuable."                                                          
## [3] "*NS509:\tHowever, when it comes down to it, it is all just paper."                                                                                              
## [4] "*NS509:\tHowever, the value of material objects is completely up to us as individuals."                                                                         
## [1] "*NS510:\tHowever, there are those that claim that any opposition towards these actions by the Australian Federal Government are in fact based on an underlying racial issue rather than an issue of economical practicality or fairness"

学習者

for(f in 1:length(NNSs)){
  result <- grep("However", NNSs[[f]])
  print(result)
}
## [1]  93 115
## [1] 75 76
## [1] 52
## integer(0)
## integer(0)
## [1] 65
## [1] 83 98
## integer(0)
## [1] 70
## [1] 52

使用例

  • 日本人のデータはうまく読み込めていない(読み込むときの区切りの指定に問題あり?)
for(f in 1:length(NNSs)){
  result <- grep("however", NNSs[[f]], value=T, ignore.case=T)
  print(result)
}
## [1] "%NTV:\tHowever, many budo have no teammate; instead, you must play against yourself."                  
## [2] "%COM:\tAvoid starting sentences with coordinating conjunctions. You can change \"but\" to \"however\"."
## [3] "%NTV:\tHowever, because of rei, budo provides many additional good points, such as mental strength."   
## [1] "*JPN502:\tHowever, we cannot study in advance because of the less time."
## [2] "%NTV:\tHowever, we could not study enough because we had less time. "   
## [1] "%NTV:\tHowever, I think we should not view it as an entirely useless and incorrect policy."
## character(0)
## character(0)
## [1] "*JPN506:\tHowever, I have heard one family story ever before."
## [1] "*JPN507:\tHowever, L make think to educational systems."                                                     
## [2] "*JPN507:\tHowever, we want more high quality working in one area, it need longer time to enhance that skill."
## character(0)
## [1] "%NTV:\tHowever, there are sports where the player's genetics is non-relative."                               
## [2] "%COM:\tDon't start sentences with coordinating conjunctions. \"But\" can often be replaced with \"however\"."
## [1] "%NTV:\tHowever, when they enter university or get a job, the situation changes."