I would like to know how to split columns in the same way as excel in the text-to-column function. There are many stackexchange tutorials on how to split columns with characters, but they don't address 3 things I need:
1). work with a column where only some of the rows have a 2) character. work with a data framework that has many columns 3). treat columns as characters / factors
For example, I have a dataframe
df <- data.frame(V1 = c("01, 02", "04", "05, 06", "07, 08", "09", "10"), V2 = c("11, 12", "14", "13, 14", 11, 14", "13", "15")
If I used text columns from V1 to excel, I would end up splitting 3 columns into a comma. The second column will be created only for those cells that have a comma in them. There will be empty cells for rows that did not have a column. I will also have the opportunity to treat the new column as a number or text. In this case, I need a leading zero, so it should be considered as text.
It will look something like this.
V1 V2 V3 Row 1 01 02 11,12 Row 2 04 NA 14
How would I do something like this in R, bearing in mind that the dataset that I have has many columns, so itβs not practical to rename each column in the code.
Hope this was clear. Thanks for the help!