I have a vector of strings x with length 4 in my R code. I concatenated the first and second element, then removed the second element from the vector. How can I remove an element from the vector entirely so that it stays of length 4? Hope that makes sense!! Not sure I'm explaining well so included to the code below.
inning <- "Valente T. flied out to lf (1-0 B). Galazin grounded out to 2B (1-2 FBS). Shaw singled through the left side (0-0). Boselli Iii flied out to cf (0-2 KF)."
inn <- unlist(strsplit(inning, "[.]"))
for (i in 1:length(inn)){
ab_length <- sapply(strsplit(inn[i], " "), length)
if(ab_length<3){
inn[i] <- paste(inn[i], inn[i+1])
inn <- inn[-(i+1)]
inn <- remove.na(inn)
} # end if
} # end for
num <- rep(0, length(inn))
It works for the above example, but let's say I change Galazin to Galazin B. Then it leaves the vector at 5 elements and doesn't concatenate Galazin B. with the remainder of the sentence. Thoughts?