A regular expression will work.
For example, suppose strthese are the lines that you want to recognize. Suppose your csv file looks like
1,1000,I, am done, with you
2,500, i don't know
If you want to read from a file, just call readLines()to read all the lines of the file as a character vector in R, just like str.
. {stringr}, .
str <- c("1,1000,I, am done, with you", "2,500, i don't know")
library(stringr)
matches <- str_match(str,pattern="(\\d+),(\\d+),\\s*(.+)")
(\\d+),(\\d+),\\s*(.+). \\d , \\s , . -. + , * "" "-". () , , .
matches,
[,1] [,2] [,3] [,4]
[1,] "1,1000,I, am done, with you" "1" "1000" "I, am done, with you"
[2,] "2,500, i don't know" "2" "500" "i don't know"
, str_match . , .
df <- data.frame(matches[,-1],stringsAsFactors=F)
colnames(df) <- c("Id","Count","Comment")
df <- transform(df,Id=as.integer(Id),Count=as.integer(Count))
df - :
Id Count Comment
1 1 1000 I, am done, with you
2 2 1002 i don't know