I have a tab delimited text file that I just can't seem to convert to a data frame.
Here's the txt file, tab-delimited, pretty standard:
Dispenser Zip\tPrescriber Zip\tDate Filled\tDate Written\tNDC Number\tDrug Name\tQuantity Dispensed\tNew/Refill Status\tDays Supply\tPayment Type\tPatient Age Group\tPatient Gender\tPatient Zip\tDrug Category\tDEA Schedule
535\t537\t4/1/2017 12:00:00 AM\t3/24/2017 12:00:00 AM\t59417010710\tLisdexamfetamine Dimesylate\t30.00\tNew\t30.00\tCommercial Insurance\t20-29\tFemale\t535\tStimulant\tSchedule II
535\t535\t4/1/2017 12:00:00 AM\t10/20/2016 12:00:00 AM\t16729013716\tClonazepam\t30.00\tRefill\t30.00\tCommercial Insurance\t60-69\tMale\t535\tBenzodiazepines\tSchedule IV
541\t543\t4/1/2017 12:00:00 AM\t2/13/2017 12:00:00 AM\t00228300350\tClonazepam\t30.00\tRefill\t30.00\tMedicaid\t60-69\tMale\t541\tBenzodiazepines\tSchedule IV
541\t541\t4/1/2017 12:00:00 AM\t11/15/2016 12:00:00 AM\t67253090111\tAlprazolam\t90.00\tRefill\t30.00\tMedicaid\t50-59\tFemale\t541\tBenzodiazepines\tSchedule IV
541\t530\t4/1/2017 12:00:00 AM\t2/28/2017 12:00:00 AM\t00071101768\tPregabalin\t60.00\tRefill\t30.00\tCommercial Insurance\t50-59\tFemale\t544\tOther\tSchedule V
I've tried:
my.data <- read.table(file = '//myfolder/my_text_file.txt', # file is in a data folder in my working directory
sep = '\t', # file is tab--delimited
header = TRUE, # the first row of the data is a header row
stringsAsFactors = FALSE)
As well as:
my.data <- read.delim( "//myfolder/my_text_file.txt", header = TRUE, sep = "\t")
And finally, I've tried:
my_text_file <- str_split_fixed(my_text_file$names, "\t", 2)
And, yet, no matter what I do, my code outputs this:
I can't seem to figure out why it's not recognizing the tab delimiter.