Reputation: 191
I have been stuck on this for hours, please give me some helps !
I got a file contains thousands of observations and they are in rows/lines (no columns)
So I do readLines and then want to extract the data that I need
#open file for data connection
data <- file("data.log", open = "r")
#do readlines for the first 6 lines tho
##there should be more than 500 lines for thousands of observations
rl <- readLines(data, 6)
the labels/headers that are not included in the data: time , group, task, complete or not, hours, credit
[1] 10:00 A task1 comp 5:00 200
[2] 16:00 A task2 comp 3:00 130
[3] 11:00 B task1 incomp 7:00 180
[4] 17:00 B task2 comp 7:00 100
[5] 15:00 C task1 incomp 5:00 420
[6] 19:00 C task2 comp 6:00 115
so there are 2 things I want to extract and then put them into a data frame. I want to get the group "A" with "comp" so I tried grep()
grep("A", data)
but I got the result: integer (0) also, how can I grep() both A and comp at the same time?
I tried :
grep "A", data | grep "comp"
grep("A" & "comp", data)
both give error!
any help would be appreciated !! thanks!
Upvotes: 0
Views: 81
Reputation: 12885
This returns the results you want from the dataset you've put in your question, but you might want to look at the help entry for grep
to see how to manipulate it further.
grep(
x = rl,
pattern = " A .* comp ",
value = TRUE
)
Upvotes: 1