我是 R 新手,在 (1) 概括以前的堆栈溢出答案以适应我的情况,以及 (2) 理解 R 文档时遇到困难。所以我转向这个社区,希望有人能引导我度过难关。
\n\n我有这个代码,其中data1有一个文本文件:
data1 <- read.delim(file.choose())\npattern <- c("An Error Has Occurred!")\nstr_detect(data1, regex(pattern, ignore_case = FALSE))\nRun Code Online (Sandbox Code Playgroud)\n\n我看到的错误消息是:
\n\nargument is not an atomic vector; coercing[1] FALSE\nRun Code Online (Sandbox Code Playgroud)\n\n当我使用 is.vector() 确认数据类型时,看起来应该没问题:
\n\nis.vector(pattern)\n#this returns [1] TRUE as the output\nRun Code Online (Sandbox Code Playgroud)\n\n我用于 str_detect 函数的参考是https://www.rdocumentation.org/packages/stringr/versions/1.4.0/topics/str_detect。
\n\n编辑 1:data1这是- I\m试图匹配第四行到最后一行“发生错误!”的输出:
Silk.Road.Forums\n<fctr>\n*\nWelcome, Guest. Please login or register.\n[ ] [ ] [Forever] [Login]\nLogin with username, password and session …Run Code Online (Sandbox Code Playgroud)