I have row data in a text file, where each row consists of 22 numerical characters. Each row consists of three different column but there is no separator. Specifically, the first two characters of the raw represent the first column of data, the subsequent 8 characters represent the second column of data and the last 12 characters represent the third column of data. An example follows: row data: 1003061490000000011608 The first two characters, "10", is the column "Regime"; the subsequent 8 characters, "03061490", is the column "Industry", and the last 12 characters, "000000011608", is the column dollar value. How do I import the column data into R without having any separator in the text file? Thanks for your help, Paolo. [[alternative HTML version deleted]]
See: ?read.fwf Example:> ff <- tempfile() > cat(file = ff, "1003061490000000011608", "1003061490000000011608", sep "\n")> read.fwf(ff, widths = c(2,8,10), colClasses = "character")V1 V2 V3 1 10 03061490 0000000116 2 10 03061490 0000000116> unlink(ff)Hth, Adrian On Thu, Jun 9, 2016 at 3:40 AM, Paolo Letizia <paolo.letizia at gmail.com> wrote:> I have row data in a text file, where each row consists of 22 numerical > characters. Each row consists of three different column but there is no > separator. Specifically, the first two characters of the raw represent the > first column of data, the subsequent 8 characters represent the second > column of data and the last 12 characters represent the third column of > data. An example follows: > > row data: > 1003061490000000011608 > > The first two characters, "10", is the column "Regime"; the subsequent 8 > characters, "03061490", is the column "Industry", and the last 12 > characters, "000000011608", is the column dollar value. How do I import the > column data into R without having any separator in the text file? > Thanks for your help, Paolo. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Adrian Dusa University of Bucharest Romanian Social Data Archive Soseaua Panduri nr.90 050663 Bucharest sector 5 Romania [[alternative HTML version deleted]]
Federman, Douglas
2016-Jun-09 12:56 UTC
[R] Importing data from a text file with no separator
?read.fwf There is a data import/export document on cran.r-project.org -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Paolo Letizia Sent: Wednesday, June 08, 2016 8:40 PM To: r-help at r-project.org Subject: [R] Importing data from a text file with no separator I have row data in a text file, where each row consists of 22 numerical characters. Each row consists of three different column but there is no separator. Specifically, the first two characters of the raw represent the first column of data, the subsequent 8 characters represent the second column of data and the last 12 characters represent the third column of data. An example follows: row data: 1003061490000000011608 The first two characters, "10", is the column "Regime"; the subsequent 8 characters, "03061490", is the column "Industry", and the last 12 characters, "000000011608", is the column dollar value. How do I import the column data into R without having any separator in the text file? Thanks for your help, Paolo. [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Duncan Murdoch
2016-Jun-09 13:10 UTC
[R] Importing data from a text file with no separator
On 09/06/2016 8:56 AM, Federman, Douglas wrote:> ?read.fwf > > There is a data import/export document on cran.r-project.orgAnd included with R distributions. It's one of the manuals, and will be accessible via the help menu in front ends that have one. Duncan Murdoch> > > > -----Original Message----- > From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Paolo Letizia > Sent: Wednesday, June 08, 2016 8:40 PM > To: r-help at r-project.org > Subject: [R] Importing data from a text file with no separator > > I have row data in a text file, where each row consists of 22 numerical characters. Each row consists of three different column but there is no separator. Specifically, the first two characters of the raw represent the first column of data, the subsequent 8 characters represent the second column of data and the last 12 characters represent the third column of data. An example follows: > > row data: > 1003061490000000011608 > > The first two characters, "10", is the column "Regime"; the subsequent 8 characters, "03061490", is the column "Industry", and the last 12 characters, "000000011608", is the column dollar value. How do I import the column data into R without having any separator in the text file? > Thanks for your help, Paolo. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >