1

i am totally new to R and want to accomplish the following task:

I want to read in a file with data similar to this:

0xD4 0x04 0x46 0x00 0x36 0x40 0x64 0x00 0x00 0x1E 0x00 0x04 0x00 0x26 0x00 0x27 0xB1 0x00

Subsequently I want to store the seperated strings in some kind of array. Afterwards these strings shall be turned into their hexidecimal representation. So the string 0xD4 becomes the value 0xd4. In another step I want to output the binary representation of each hex value, e.g.:

0xD4: 11010100

I struggle reading in the data. I only know of read.table and tried:

values = read.table("file", sep=" ", headers=FALSE)

But the representation of values seems strange. And I do not know how to proceed from there.

Any help would be appreciated!

user1192748
  • 945
  • 3
  • 15
  • 26

1 Answers1

0

You probably want to read in the file as follows:

values = read.table("file", sep=" ", headers=FALSE, stringsAsFactors= F )

Then you can simply do

values <- as.numeric( values )

Regarding binary representation, see this question.

Community
  • 1
  • 1
January
  • 16,320
  • 6
  • 52
  • 74
  • Well doing this returns an error. I managed to do it by executing this code: raw <- scan(file=file2read, what="", sep=" ") values <- as.numeric(raw) for(element in values){ # Extract binary representation bin_element <- rev(as.integer(intToBits(element)))[c(25:32)] } – user1192748 Oct 24 '12 at 11:53