You can use concat.split
from my "splitstackshape" package for a more convenient way to do what you're trying to do. Assuming your data.frame
is called "mydf" and the first column is called "V1", you can do:
> library(splitstackshape)
> concat.split(mydf, "V1", sep = ".", drop = TRUE)
V2 V1_1 V1_2 V1_3
1 74 1880 1 1
2 74 1881 1 1
3 75 1882 1 1
4 79 1883 1 1
5 111 1884 1 1
6 145 1885 1 1
Here, "mydf" is defined as:
mydf <- structure(list(V1 = c("1880.1.1", "1881.1.1", "1882.1.1", "1883.1.1",
"1884.1.1", "1885.1.1"), V2 = c(74L, 74L, 75L, 79L, 111L, 145L)),
.Names = c("V1", "V2"), class = "data.frame", row.names = c(NA, -6L))
The equivalent in base R is to use something like the following:
> cbind(read.table(text = as.character(mydf$V1), sep = "."), mydf[-1])
V1 V2 V3 V2
1 1880 1 1 74
2 1881 1 1 74
3 1882 1 1 75
4 1883 1 1 79
5 1884 1 1 111
6 1885 1 1 145