I have been given a dataset as a .txt format that I need to import in R for a research analysis. The .txt file has one column with numeric characters, no header, and no delimiter. These are a couple of the examples in the .txt file:
4878578572809275874037093859845083594859474905704627402739385785748756 0934893758795493758745846784678576857458708476968983984980985974687586 3989458476857609379087685796847586770493706759787398499485957658968590
I want to know how I can separate these characters in R according to its variables. So, I want to separate the first 3 numbers to be for variable 1, the next 5 numbers to be for variable 2, the next 2 numbers to be for variable 3, and so on.
Is there an expression I can use in R that will allow for me to separate the observations in the .txt file according to its required number of characters for each variable?
I have tried read.fwf but it did not work. Or maybe I tried it incorrectly.
Help with this issue will be much appreciated!
You can use the substring function.