Skip to content

Instantly share code, notes, and snippets.

@pinetum
Last active April 21, 2020 10:38
Show Gist options
  • Save pinetum/0f63ea7048f24889cdd9a170a7e77163 to your computer and use it in GitHub Desktop.
Save pinetum/0f63ea7048f24889cdd9a170a7e77163 to your computer and use it in GitHub Desktop.
Read binary file in R (4byte float point)
path_binary_file <- "~/Dropbox/元智課程資料/研究所課程/資料探勘/VQ/COL.sil"
n_dimension <- 26
n_element_byte <- 4
#------read file-----
#create file connection
zz <- file(path_binary_file, "rb")
# calculate number of element bt file size
n_total_element <- file.info(path_binary_file)$size/n_element_byte
x <- matrix(readBin(zz, what="double", size=n_element_byte, n=n_total_element), ncol = n_dimension)
close(zz)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment