Question

I have data frame like this

vf<-data.frame(A=c("v1v2"),B=c("v2v3"))

is it possible to split the content as v1 and v2 ..etc ..into two columns.

I used ddply ,but how different number separated?

expected out put

enter image description here

Also I stored my row name as variable

na<-rownames(vf)

It stored as "1", so I can't use it as vf[na]..

How can I store my row name in a variable and use it in function rownames()?

Was it helpful?

Solution

 vf$A.1 <- substr(vf[,1], 1,2)
 vf$A.2 <- substr(vf[,1], 3,4)


#> vf
#     A    B A.1 A.2
#1 v1v2 v2v3  v1  v2
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top