mark.hogue at srs.gov
2014-Oct-08 11:02 UTC
[R] reading in hexadecimal data - not working with data ending in E
I am trying to read in data from an instrument that is recorded in hexadecimal format. Using either: y.hex <- read.table(file="hex.data", as.is=TRUE) or y.hex <- read.table(file="hex.data", text=TRUE) gets all the data in just fine except points like `055E` or `020E`. In these cases, the E is stripped so I get just 055 or 020. The question is how should this data be imported to avoid the E-ending problem? (By the way, my follow-up is to convert this data using, `y <- strtoi(y.hex, 16L)`) Thanks for any suggestions, Mark Hogue [[alternative HTML version deleted]]
Duncan Murdoch
2014-Oct-08 19:57 UTC
[R] reading in hexadecimal data - not working with data ending in E
On 08/10/2014 7:02 AM, mark.hogue at srs.gov wrote:> I am trying to read in data from an instrument that is recorded in > hexadecimal format. Using either: > > y.hex <- read.table(file="hex.data", as.is=TRUE) > > or > > y.hex <- read.table(file="hex.data", text=TRUE) > > gets all the data in just fine except points like `055E` or `020E`. In > these cases, the E is stripped so I get just 055 or 020.You need to read the ?read.table help. as.is and text don't do anything like what you want. The argument you need to use is colClasses. I think you want to set it to "character". Duncan Murdoch> > The question is how should this data be imported to avoid the E-ending > problem? > > (By the way, my follow-up is to convert this data using, `y <- > strtoi(y.hex, 16L)`) > > Thanks for any suggestions, > > Mark Hogue > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > 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.
William Dunlap
2014-Oct-08 19:58 UTC
[R] reading in hexadecimal data - not working with data ending in E
I did not see a reproducible example, but you should use colClasses="character" to read in the data as character, then use something like as.hexmode() to convert it to integers. E.g., > z <- read.table(text="ColA ColB\n1e 33\n2e 44\n10 5e\n", header=TRUE, colClasses="character") > str(z) 'data.frame': 3 obs. of 2 variables: $ ColA: chr "1e" "2e" "10" $ ColB: chr "33" "44" "5e" > z[] <- lapply(z, function(zi)as.integer(as.hexmode(zi))) > str(z) 'data.frame': 3 obs. of 2 variables: $ ColA: int 30 46 16 $ ColB: int 51 68 94 If you leave out the colClasses="character" then read.table will say that all those strings look like decimal numerals ("1e" being read as "1e+0", giving 1*10^0). Bill Dunlap TIBCO Software wdunlap tibco.com On Wed, Oct 8, 2014 at 4:02 AM, <mark.hogue at srs.gov> wrote:> I am trying to read in data from an instrument that is recorded in > hexadecimal format. Using either: > > y.hex <- read.table(file="hex.data", as.is=TRUE) > > or > > y.hex <- read.table(file="hex.data", text=TRUE) > > gets all the data in just fine except points like `055E` or `020E`. In > these cases, the E is stripped so I get just 055 or 020. > > The question is how should this data be imported to avoid the E-ending > problem? > > (By the way, my follow-up is to convert this data using, `y <- > strtoi(y.hex, 16L)`) > > Thanks for any suggestions, > > Mark Hogue > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > 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.
John McKown
2014-Oct-08 20:04 UTC
[R] reading in hexadecimal data - not working with data ending in E
On Wed, Oct 8, 2014 at 6:02 AM, <mark.hogue at srs.gov> wrote:> I am trying to read in data from an instrument that is recorded in > hexadecimal format. Using either: > > y.hex <- read.table(file="hex.data", as.is=TRUE) > > or > > y.hex <- read.table(file="hex.data", text=TRUE) > > gets all the data in just fine except points like `055E` or `020E`. In > these cases, the E is stripped so I get just 055 or 020. > > The question is how should this data be imported to avoid the E-ending > problem? > > (By the way, my follow-up is to convert this data using, `y <- > strtoi(y.hex, 16L)`) > > Thanks for any suggestions, >?Please don't post in HTML, it is against forum policy. And it often results in poorly formatted messages, which many ignore.? ?Try: y.hex <- read.table(file="hex.data",as.is=TRUE,colClasses="character");?> > Mark Hogue >-- There is nothing more pleasant than traveling and meeting new people! Genghis Khan Maranatha! <>< John McKown [[alternative HTML version deleted]]