R R.scripts !!!co2list CHATファイル内の分析コード(%co2: )の抽出 {{pre co2list <- function() { token.all <- "" files <- list.files() for (i in files) { token <- "" lines.tmp <- scan(i, what="char", sep="\n") body.tmp <- grep("^%co2", lines.tmp, value=T) body.tmp2 <- gsub("%co2:\t", "", body.tmp) body.tmp2 <- gsub("\\s+", " ", body.tmp2) #複数のペースを一つに token.all <- c(token.all, body.tmp2) } code.list <- sort(token.all) code.list <- code.list[code.list != ""] as.data.frame(code.list) } }} !co2list2 *月齢とともにコードを抽出 {{pre > co2list2 <- function() { token.all <- "" files <- list.files() for (i in files) { token <- "" lines.tmp <- scan(i, what="char", sep="\n") #月齢の取得 geturei.tmp <- grep("^@ID:\t.*CHI", lines.tmp, value=T) geturei.tmp2 <- gsub("^@ID:\t.*CHI\\|", "", geturei.tmp) geturei.tmp3 <- gsub("\\|.+", "", geturei.tmp2) body.tmp <- grep("^%co2", lines.tmp, value=T) body.tmp2 <- gsub("%co2:\t", "", body.tmp) body.tmp2 <- gsub("\\s+", " ", body.tmp2) #複数のペースを一つに getureiTabCodeItem <- paste(geturei.tmp3, body.tmp2, sep="\t") token.all <- c(token.all, getureiTabCodeItem) } code.list <- sort(token.all) code.list <- code.list[code.list != ""] as.data.frame(code.list) } }}