Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8724299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:48:05+00:00 2026-06-13T07:48:05+00:00

please download the file in the https://www.box.com/s/z3tldpdykhppmivfexjl ,save it as ‘/tmp/mydata’ and run the

  • 0

please download the file in the
https://www.box.com/s/z3tldpdykhppmivfexjl

,save it as ‘/tmp/mydata’
and run the following code

datafile="/tmp/mydata"
totalsize=file.info(datafile)$size
lines=totalsize/32
con=file(datafile,"rb")
date<-c()
data<-c()
for (i in 1:lines){
    result1<-readBin(con,integer(),n=1,size=4,endian="little")
    date<-c(date,result1)
    result2<-round(readBin(con,double(),n=7,size=4,endian="little"),2)
    data<-c(data,result2)
}
date=data.frame(matrix(date,nrow=lines,ncol=1,byrow=TRUE))
data=data.frame(matrix(round(data,2),nrow=lines,ncol=7,byrow=TRUE))
data=cbind(date,data)
names(data)<-c("date","open","high","low","close","volume","amount","reserved")
data<-data[-c(1:2),]

when you finish ,please input data in R console,
you can see long digits,
https://www.box.com/s/lxkbs96vk02p6ekdflbe
enter image description here
why round(data,2) can not round 2 digits?
it is so strange ,when i write the data into a csv file,open the csv file,i found it has only 2 digits!

write.csv(file="/tmp/test",data)

Joris Meys say it is bad way to grow vector in for-loops,but i find maybe in my case it is good way to do that ,if not ,how to revise it?let me see the better codes.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:48:06+00:00Added an answer on June 13, 2026 at 7:48 am

    On the issue about growing the loop, one option is to put everything into a list if you don’t know the length of each binary vector read in (as I don’t because I have not downloaded your data nor run your code!). Once in a list you can go to a compact form after if each element read in is of the same length, or in this case if all you want is a vector, just unlist() each list.

    datafile <- "/tmp/mydata"
    totalsize <- file.info(datafile)$size
    lines <- totalsize / 32
    con <- file(datafile, "rb")
    ## allocate storage
    date <- data <- vector(mode = "list", length = lines)
    ## although actually growing lists is not inefficient
    for (i in 1:lines){
        ## directly fill in the lists we created using index i to point
        ## to the ith component of each list
        date[[i]] <- readBin(con, integer(), n=1, size=4, endian="little")
        data[[i]] <- round(readBin(con,double(), n=7, size=4, endian="little"), 2)
    }
    

    At this point you have two lists and if you want them compact-ified into a vector do

    date <- unlist(date)
    data <- unlist(date)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please download the following code : http://media.pragprog.com/titles/eband3/code/Sudokuv2/src/org/example/sudoku/PuzzleView.java In the code, What initial value does
Explain me please how to download a file from a server using SSL (https://).
Download JQGrid js file from http://www.trirand.com/blog/ . Is it free? What is this http://www.trirand.net/demoaspnetmvc.aspx
i want get extension file of url . for example get extension http://www.iranfairco.com/download-file/02912bb889cb24 .
My PHP knowledge is limited and I am trying to implement http://www.tutorialchip.com/php-download-file-script/ this script
I have a url of a website. It looks something like this: http://www.example.com/downloads/file/4789/download ?
I have a XML File in the following format: <?xml version='1.0' encoding='UTF-8'?> <entry xmlns='http://www.w3.org/2005/Atom'
wget http://www.example.com/file.doc downloads that file to the local disk. What is the equivalent of
Whenever I call the webservice: http://www.grubolympx.com/app/rating.php , it sends Please send appropriate value message.
when i want to run my xhtml file, firefox file download is running inside

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.