> # read data in, and only select the 4th line to pass to grep() > cat("Document 1 of 100 \n \n \n Newspaper Name \n \n Day Date", file = > Maybe I don't understand properly.if you are doing this in R, can't I'll just have to come up with a loop to tell R to get the 4th, 8th, 12, 16th, line, etc. But your idea of indexing the text object read into R with the line number where the newspaper name is found is a good one. > I'm using readlines to get the text file into R and then trying to use grep to get the newspaper name for each record. > The file that I have includes up to 100 documents (Document 1, Document 2, Document 3.Document 100) with the newspaper name following 4 lines below each Document number. > Sorry for the insufficient introduction. > should give you 4 lines after each line where Document occurred. > grep("Document .", yourfile, value = FALSE) 4 > If you know you can find the start of the document (say that line I could do two separate commands, but I'd like to know if this could be done in one command. Is there any way to have it grab two different lines after the grep, say the second and the fourth line? There's some other information in the text file I'd like to grab. > If you want a sufficient number of lines that manually writing index becomes cumbersome, you could use something like: > index index > You just need to make sure you avoid recycling, e.g., > Try this (untested as I'm on my iPhone now): and Josh's solution can be shortened to (as he knows): Please read theĭocs, especially the tutorial, An Intro to R.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |