Searching for string within a text file in R [closed]

房东的猫 提交于 2019-11-30 22:53:37

1) Read it in and use R's grep:

 # test input
 cat("a 1\n\b 2\nc 3\n", file = "myfile.dat")


 grep("a", readLines("myfile.dat"), value = TRUE)
 ## [1] "a 1"

2) Another possibility if you have grep on your system and on the search path is:

 shell("grep a myfile.dat")
 ## a 1

On Windows you could use findstr in place of grep or if you have Rtools installed but not on your path shell("C:\\Rtools\\bin\\grep a myfile.dat").

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!