Stitching together badly formatted log files
Without knowing exactly your data structure, I have to guess that it looks like this:

data &lt;- data.table(a = c('1,1,1,4,6',
                         '1,2,3,4,',
                         '',
                         '1,2,3,4,',
                         '1,2,3,4,5'))


If it is correct, then your desired operations could be done like this:

#############################################
#Removing empty rows.
data &lt;- data[data[[1]] != '']

#Removing rows where there is no data in the 5th column. 
retain &lt;- str_detect(trimws(data[[1]], which = 'both') ,".+,.+,.*,.*,.+")
data &lt;- data[retain, ]

#This replaces the first 4 commas with a tab-delimiter. 
for(i in 1:4) data[[1]] &lt;- str_replace(data[[1]], ",", "\t")

#This splits the row into 5 seperate columns, always. 
dNew &lt;- as.data.table(tstrsplit(data[[1]], "\t", fixed = T))
dNew
#    V1 V2 V3 V4 V5
# 1:  1  1  1  4  6
# 2:  1  2  3  4  5


The main problem is that you are using lapply where it is not needed.