I have a character column in my data framework that looks like
df<- data.frame(a=c("AaBbCC","AABBCC","AAbbCC"))
I would like to split this column every two characters. Therefore, in this case, I would like to get three columns named VA,VB,VC . I tried
library(tidyr) library(dplyr) df<- data.frame(a=c("AaBbCC","AABBCC","AAbbCC"))%>% separate(a,c(paste("V",LETTERS[1:3],sep="")),sep=c(2,2)) VA VB VC 1 Aa BbCC 2 AA BBCC 3 AA bbCC
but this is not the desired result. I like to have the result, which is now in VC , split into VB (all letters B) and VC (all letters C). How do I get R to split every two characters. The row length in the column is always the same for each row (6 in this example). I will have lines 10 in length.
source share