in Education by
I wish to Import 100 text files from a website , but how do I wrangle them into the format I need. Here is a sample of the data: NOTE: futures symbols begin with the character @ index symbols begin with the character $ Symbol (option symbols) hv20 hv50 hv100 DATE curiv Days/Percentile Close **************************************************************** * Data generated by McMillan Analysis Corp. Copyright 2019 * * www.optionstrategist.com 800-724-1817 * **************************************************************** $BKX 22 18 22 190211 21.42 15/ 20%ile 91.76 $DJX 10 11 20 190322 16.24 600/ 84%ile 255.02 $HGX 16 15 23 190322 22.61 378/ 70%ile 286.36 $MNX the files are from a subscription website and are saved as text eg. vh_sym_20190322, If anyone could help me it would be appreciated. I not only need to download bulk text files but then I need to wrangle them so that I only have the headers eg. "Symbol", "hv28" etc, and the data with Symbols and numbers eg. "$BKX", "22" etc, thanks again to anyone who can offer assistance. PS. I subscribe to this companies data. JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)

1 Answer

0 votes
by
Assuming a file just like that, this works: cn <- read.fwf("~/Downloads/foo.txt", c(34, 4, 6, 6, 8, 8, 16, 6), skip=3, comment.char="*", header=F, n=1) cn # V1 V2 V3 V4 V5 V6 V7 # 1 Symbol (option symbols) hv20 hv50 hv100 DATE curiv Days/Percentile # V8 # 1 Close cn <- make.names(trimws(unlist(cn))) cn # [1] "Symbol..option.symbols." "hv20" "hv50" # [4] "hv100" "DATE" "curiv" # [7] "Days.Percentile" "Close" dat <- read.fwf("~/Downloads/foo.txt", c(34, 4, 6, 6, 8, 8, 16, 6), skip=4, comment.char="*", header=FALSE) colnames(dat) <- cn str(dat) # 'data.frame': 3 obs. of 8 variables: # $ Symbol..option.symbols.: Factor w/ 3 levels "$BKX ",..: 1 2 3 # $ hv20 : int 22 10 16 # $ hv50 : int 18 11 15 # $ hv100 : int 22 20 23 # $ DATE : int 190211 190322 190322 # $ curiv : num 21.4 16.2 22.6 # $ Days.Percentile : Factor w/ 3 levels " 15/ 20%ile ",..: 1 3 2 # $ Close : num 91.8 255 286.4 You may want to update the column names and/or include stringsAsFactors=FALSE. After that, you'll have a bit of data-cleaning, for example Days.Percentile appears to be a combined cell that was less-trivial to clean up with fixed-width reading alone.

Related questions

0 votes
    I wish to Import 100 text files from a website , but how do I wrangle them into the format I ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 16, 2022 in Education by JackTerrance
0 votes
    1. Write a function in python to read the content from a text file “poem.txt” line by line and display the same on screen Select the correct answer from above options...
asked Dec 1, 2021 in Education by JackTerrance
0 votes
    read the data from employee. text file and sort on age using counting sort,merge sort,quick sort and write ... sortedemponage.txt'. Select the correct answer from above options...
asked Dec 22, 2021 in Education by JackTerrance
0 votes
    Let's say, I have a folder called maps and inside maps I have map1.txt, map2.txt, and map3.txt. ... , JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Jul 8, 2022 in Education by JackTerrance
0 votes
    Which component do you need to use in order to read data line by line from an input flow ... entries into iterative global variables? tIterateToFlow tFileList tFlowToIterate tLoop...
asked Mar 24, 2021 in Technology by JackTerrance
0 votes
    I have a file that looks like this: NODE=SC-1,CPU=90 NODE=SC-1,MEM=10 NODE=SC-1,FS=80 ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I have a file that looks like this: NODE=SC-1,CPU=90 NODE=SC-1,MEM=10 NODE=SC-1,FS=80 ... questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Feb 13, 2022 in Education by JackTerrance
0 votes
    I am a beginner and I just need a bit of help on why I getline is showing an error: this is what I have so far ... payments[MAX_ITEMS]; ifstream iFile; if ( argc != 2 ) { cout...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    I am a beginner and I just need a bit of help on why I getline is showing an error: this is what I have so far ... payments[MAX_ITEMS]; ifstream iFile; if ( argc != 2 ) { cout...
asked Apr 7, 2022 in Education by JackTerrance
0 votes
    Can someone tell me how to find all the files in directory with .txt extension in Python? Select the correct answer from above options...
asked Jan 23, 2022 in Education by JackTerrance
0 votes
    Which of the following function is used to read data off the webpages? (a) read.web (b) read.Lines ... questions and answers pdf, Data Science interview questions for beginners...
asked Oct 28, 2021 in Education by JackTerrance
0 votes
    Is there a nicer way to write the following function fs' with functors or applicatives? fncnB = (* ... Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Apr 21, 2022 in Education by JackTerrance
0 votes
    Which of the following code opens a connection to the file foo.txt, reads from it, and closes the connection when its done? (a) data...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    Which of the following R code creates a connection to ‘foo.txt’? (a) con...
asked Feb 15, 2022 in Education by JackTerrance
0 votes
    For example, I have an ASP.NET form that is called by another aspx: string url = "http:// ... JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)...
asked Mar 21, 2022 in Education by JackTerrance
...