Selecting and modifying rows in a dataframe based on criteria
You can do :
temp <- X[substring(X$V1, 2, 2) == 5, ]
So answer to question a) is: temp$V1
and question b) is: temp$V2
For question c), we can use substring
to paste 1st to 3rd letter of V2
, insert "X" in between and the remaining string to create new column as V3
.
temp$V3 <- paste0(substring(temp$V2, 1, 3), 'X', substring(temp$V2, 4))