I'm having a file with many lines, which I want to transform in a data frame to do some data science.
Reading line by line I founding a little code snippet, which not seems to be working well. But that is not the main problem. First of all, i want only save the lines which are having the string "CANFD" inside. And I know that is not working with a standard if construct, because of the vector. The substring is working and yes the numbers are correct.
fileName <- "Data2F001new.ASC"
conn <- file(fileName,open="r")
linn <-readLines(conn)
for (i in 1:length(linn)){
{
tmp <- substring(linn, 12, 16)
if(tmp=="CANFD"){
system <- substring(linn, 12, 16)
timestamp <- substring(linn, 0, 10)
bytes <- substring(linn, 54, 56)
channel <- substring(linn, 19,20)
}
}
close(conn)
R says me following: The condition has length > 1 and only the first element will be used. The expected Output are the lines with CANFD.