Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用grep--R获取不断变化的模式_R_Pattern Matching - Fatal编程技术网

使用grep--R获取不断变化的模式

使用grep--R获取不断变化的模式,r,pattern-matching,R,Pattern Matching,我想用grep的答案键给几个学生的考试打分。例如,学生的答案是 A B B C E D D 关键是 A D B C E CD ABD 我想检查学生的答案是否在答案键的相应位置(多个字母表示“或“不”和“.So”C或“D”)。我是如何使用grep的?我们可以使用purrr软件包中的map2\u lgl函数和greplTRUE表示发现答案与密钥匹配FALSE表示不匹配 # Create example of answer and key answer <- c("A", "B", "B",

我想用grep的答案键给几个学生的考试打分。例如,学生的答案是

A B B C E D D
关键是

A D B C E CD ABD

我想检查学生的答案是否在答案键的相应位置(多个字母表示“或“不”和“.So”C或“D”)。我是如何使用grep的?

我们可以使用
purrr
软件包中的
map2\u lgl
函数和
grepl
TRUE
表示发现答案与密钥匹配
FALSE
表示不匹配

# Create example of answer and key
answer <- c("A", "B", "B", "C", "E", "D", "D") 
key <- c("A", "D", "B", "C", "E", "CD", "ABD")

# Load packages
library(purrr)

# Check if answer is in key
map2_lgl(answer, key, ~grepl(.x, .y))
[1]  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
#创建答案和关键点示例

回答我们可以使用
purrr
软件包中的
map2\u lgl
功能,使用
grepl
TRUE
表示发现答案与密钥匹配
FALSE
表示不匹配

# Create example of answer and key
answer <- c("A", "B", "B", "C", "E", "D", "D") 
key <- c("A", "D", "B", "C", "E", "CD", "ABD")

# Load packages
library(purrr)

# Check if answer is in key
map2_lgl(answer, key, ~grepl(.x, .y))
[1]  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
#创建答案和关键点示例

回答或者我们可以使用
Map/mappy
from
base R

unname(mapply(grepl, answer, key))
#[1]  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
数据
answer或者我们可以使用
Map/mappy
from
base R

unname(mapply(grepl, answer, key))
#[1]  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
数据
回答输出应该是什么样子?到目前为止,您尝试了什么?输出应该是什么样子的?到目前为止你做了什么?