I want to be able to remove specific characters from items in my data frame.
Sample <- c("A1.1","B1.1","C1.1","A1.2","B1.2","C1.2")
X <- c(1,1,2,4,3,5)
df <- data.frame(Sample, X)
Sample X
1 A1.1 1
2 B1.1 1
3 C1.1 2
4 A1.2 4
5 B1.2 3
6 C1.2 5
I want to remove the ".1" and ".2" (or the 3rd and 4th character) from each item in the Sample column.
df$Sample <- gsub(".1","",as.character(df$Sample))
df
Sample X
1 1
2 1
3 2
4 .2 4
5 .2 3
6 .2 5
This is what I've tried so far but doesn't do what I want. Is there a way to just remove the 3rd and 4th character from each item in the Sample column?