I am relatively new to R and am attempting to turn a text file with a long character string into a single column of a data table with one character per row. I have tried reading in the text file using read_file from the readr package and then making the character string a list and finally using cbind, as below:
df <- data.frame("id" = 1:9)
string <-read_file("StringFilePath.txt")
string <- as.list(string)
df <- cbind(df, string)
Unfortunately, I end up with all of the characters in the string in the first row of the data frame. I have also attempted, perhaps misguidedly, to add a comma between each character and then create a .csv file that I could more easily work with as below:
string <- gsub("(?<=.)(?=.)", ",", string, perl = TRUE)
write.csv(string, "StringFilePath.csv",
row.names = FALSE)
However, the .csv ended up with roughly half of the characters in the first row for reasons that escape me. Any suggestions for a solution to this seemingly simple problem would be greatly appreciated!