shyquote does not work! What to do? - r

I would like to convert the following list into a list where all names are between " " (spaces)
I tried shQuote, gsub(" ", "", ) and these methods; Creating a comma separated vector, but no success so far...
George Ezra, Faith No More, Above & Beyond, Paloma Faith, Gavin James, DJ’s Waxfiend, Jebroer, Adje, Pop Evil, Jick munro & the amazing laserbeams, Robbie Williams, Avicii, The Script, Anouk, Kensington, Eagles of Death Metal, Dotan, The Wombats, Selah Sue, Shappard, John Coffey, Magic!, Joost van Bellen, East Camoran Folkcore, Foo Fighters, Pharrel Williams, Sam Smith, One Republic, Rise Agianst, De Jeugd van Tegenwoordig, Counting Crows, Fiddler’s Green, Thyphoon, Kovacs, Kitty, Daisy & Lewis, Oscar and the Wolf, Nick Mulvey, Urbanus, Willie Wartaal, Doppelgang, Ewert and the two dragons, Pierce Brothers,Kovacs, The Kendolls, Stringcaster, Sunday Sun, Toy Dolls, A$AP Rocky, Ride, Eskmo, Temples, The Pop Group, Blank Mass, Cairo Liberation Front, Daniel Norgren, Follakzoid, Ghost Culture, John Coffey, Kevin Morby, Kuenta I Tambu, Marmozets, Mourn, Patten, Sue The Night, The Coathangers, Tora, Vessels, The Libertines, Noel Gallagher’s High Flying Brids, Noel Gallagher, AltJ, Altj, Royal Blood, Sohn, The Jesus & Mary Chain, The Tallest Man On Earth, Black Mountain, Chet Faker, Death Cab For Cutie, Ear Sweatshirt, Evian Christ, Frist Aid Kit, Future Islands, Jonny Greenwood, Mew, Of Monsters And Men, The Vaccines, Ariel Pink, Alvvays, Wolf Alice, Weval, BADBADNOTGOOD, Bass Drum Of Death, Yak, Daniel Romand, Dan Dercon, Eagulls, Gengahr, Fickle friends, Steve Gunn, Liima, Hookworms, Kate Tempest, Kiasmds, Strand of Oaks, Little May , Matthew E. White, Metz, Off!, St. Paul, St. Paul & The Broken Bones, Pissed Jeans, Pretty Vicious, Reigning Sound, Outfit, Sunset Sons, Waxahatchee, Daniel Wilson, Yung Lean, Kindess, Hinds,Damien Rice, The War On Drugs, Iggy Pop, FKA Twigs, Patti Smith And Her Band Perform Horses, Flying Lotus, Fat Freddy’s Drop, Damian Jr Gong Marley, Alabama Shakes, The Gaslamp Killer, Max Richter, Motorpsycho, Goat, Songhoy Blues, Andrew Brid, Glass Animals, King Gizzard & The Lizard Wizard, Misun, JD MCPherson, Happyness, Dolomite Minor, Meridian Brothers, Death From Above 1979, Blaudzun, Oscar And The Wolf, Clark, Ghost Poet, Omar Souleyman, Rhye, Bejamin Booker, Orkesta Mendoza, Ganz,The Chemical Brothers, Patrick Watson, Bleachers, The War on Drugs, The Antlers, Hot Chip, Rico & Sticks, Awolnation

A simple strsplit() will do.
my.bands <- "George Ezra, Faith No More, Above & Beyond, Paloma Faith, Gavin James, DJ’s Waxfiend, Jebroer, Adje, Pop Evil, Jick munro & the amazing laserbeams, Robbie Williams, Avicii, The Script, Anouk, Kensington, Eagles of Death Metal, Dotan, The Wombats, Selah Sue, Shappard, John Coffey, Magic!, Joost van Bellen, East Camoran Folkcore, Foo Fighters, Pharrel Williams, Sam Smith, One Republic, Rise Agianst, De Jeugd van Tegenwoordig, Counting Crows, Fiddler’s Green, Thyphoon, Kovacs, Kitty, Daisy & Lewis, Oscar and the Wolf, Nick Mulvey, Urbanus, Willie Wartaal, Doppelgang, Ewert and the two dragons, Pierce Brothers,Kovacs, The Kendolls, Stringcaster, Sunday Sun, Toy Dolls, A$AP Rocky, Ride, Eskmo, Temples, The Pop Group, Blank Mass, Cairo Liberation Front, Daniel Norgren, Follakzoid, Ghost Culture, John Coffey, Kevin Morby, Kuenta I Tambu, Marmozets, Mourn, Patten, Sue The Night, The Coathangers, Tora, Vessels, The Libertines, Noel Gallagher’s High Flying Brids, Noel Gallagher, AltJ, Altj, Royal Blood, Sohn, The Jesus & Mary Chain, The Tallest Man On Earth, Black Mountain, Chet Faker, Death Cab For Cutie, Ear Sweatshirt, Evian Christ, Frist Aid Kit, Future Islands, Jonny Greenwood, Mew, Of Monsters And Men, The Vaccines, Ariel Pink, Alvvays, Wolf Alice, Weval, BADBADNOTGOOD, Bass Drum Of Death, Yak, Daniel Romand, Dan Dercon, Eagulls, Gengahr, Fickle friends, Steve Gunn, Liima, Hookworms, Kate Tempest, Kiasmds, Strand of Oaks, Little May , Matthew E. White, Metz, Off!, St. Paul, St. Paul & The Broken Bones, Pissed Jeans, Pretty Vicious, Reigning Sound, Outfit, Sunset Sons, Waxahatchee, Daniel Wilson, Yung Lean, Kindess, Hinds,Damien Rice, The War On Drugs, Iggy Pop, FKA Twigs, Patti Smith And Her Band Perform Horses, Flying Lotus, Fat Freddy’s Drop, Damian Jr Gong Marley, Alabama Shakes, The Gaslamp Killer, Max Richter, Motorpsycho, Goat, Songhoy Blues, Andrew Brid, Glass Animals, King Gizzard & The Lizard Wizard, Misun, JD MCPherson, Happyness, Dolomite Minor, Meridian Brothers, Death From Above 1979, Blaudzun, Oscar And The Wolf, Clark, Ghost Poet, Omar Souleyman, Rhye, Bejamin Booker, Orkesta Mendoza, Ganz,The Chemical Brothers, Patrick Watson, Bleachers, The War on Drugs, The Antlers, Hot Chip, Rico & Sticks, Awolnation"
my.bands.vector <- strsplit(my.bands, ', ')[[1]] ## you could probably stop here, but you asked for a list, which means something specific in R
my.bands.list <- as.list(my.bands.vector)
> str(my.bands.list)
List of 159
$ : chr "George Ezra"
$ : chr "Faith No More"
$ : chr "Above & Beyond"
$ : chr "Paloma Faith"
$ : chr "Gavin James"
[list output truncated]
And if you want to convert back to a string with 's in the string:
paste(shQuote(my.bands.list, type = "sh"), collapse = ', ')
[1] "'George Ezra', 'Faith No More', 'Above & Beyond', 'Paloma Faith', 'Gavin James', 'DJ’s Waxfiend', 'Jebroer', 'Adje', 'Pop Evil', 'Jick munro & the amazing laserbeams', 'Robbie Williams', 'Avicii', 'The Script', 'Anouk', 'Kensington', 'Eagles of Death Metal', 'Dotan', 'The Wombats', 'Selah Sue', 'Shappard', 'John Coffey', 'Magic!', 'Joost van Bellen', 'East Camoran Folkcore', 'Foo Fighters', 'Pharrel Williams', 'Sam Smith', 'One Republic', 'Rise Agianst', 'De Jeugd van Tegenwoordig', 'Counting Crows', 'Fiddler’s Green', 'Thyphoon', 'Kovacs', 'Kitty', 'Daisy & Lewis', 'Oscar and the Wolf', 'Nick Mulvey', 'Urbanus', 'Willie Wartaal', 'Doppelgang', 'Ewert and the two dragons', 'Pierce Brothers,Kovacs', 'The Kendolls', 'Stringcaster', 'Sunday Sun', 'Toy Dolls', 'A$AP Rocky', 'Ride', 'Eskmo', 'Temples', 'The Pop Group', 'Blank Mass', 'Cairo Liberation Front', 'Daniel Norgren', 'Follakzoid', 'Ghost Culture', 'John Coffey', 'Kevin Morby', 'Kuenta I Tambu', 'Marmozets', 'Mourn', 'Patten', 'Sue The Night', 'The Coathangers', 'Tora', 'Vessels', 'The Libertines', 'Noel Gallagher’s High Flying Brids', 'Noel Gallagher', 'AltJ', 'Altj', 'Royal Blood', 'Sohn', 'The Jesus & Mary Chain', 'The Tallest Man On Earth', 'Black Mountain', 'Chet Faker', 'Death Cab For Cutie', 'Ear Sweatshirt', 'Evian Christ', 'Frist Aid Kit', 'Future Islands', 'Jonny Greenwood', 'Mew', 'Of Monsters And Men', 'The Vaccines', 'Ariel Pink', 'Alvvays', 'Wolf Alice', 'Weval', 'BADBADNOTGOOD', 'Bass Drum Of Death', 'Yak', 'Daniel Romand', 'Dan Dercon', 'Eagulls', 'Gengahr', 'Fickle friends', 'Steve Gunn', 'Liima', 'Hookworms', 'Kate Tempest', 'Kiasmds', 'Strand of Oaks', 'Little May ', 'Matthew E. White', 'Metz', 'Off!', 'St. Paul', 'St. Paul & The Broken Bones', 'Pissed Jeans', 'Pretty Vicious', 'Reigning Sound', 'Outfit', 'Sunset Sons', 'Waxahatchee', 'Daniel Wilson', 'Yung Lean', 'Kindess', 'Hinds,Damien Rice', 'The War On Drugs', 'Iggy Pop', 'FKA Twigs', 'Patti Smith And Her Band Perform Horses', 'Flying Lotus', 'Fat Freddy’s Drop', 'Damian Jr Gong Marley', 'Alabama Shakes', 'The Gaslamp Killer', 'Max Richter', 'Motorpsycho', 'Goat', 'Songhoy Blues', 'Andrew Brid', 'Glass Animals', 'King Gizzard & The Lizard Wizard', 'Misun', 'JD MCPherson', 'Happyness', 'Dolomite Minor', 'Meridian Brothers', 'Death From Above 1979', 'Blaudzun', 'Oscar And The Wolf', 'Clark', 'Ghost Poet', 'Omar Souleyman', 'Rhye', 'Bejamin Booker', 'Orkesta Mendoza', 'Ganz,The Chemical Brothers', 'Patrick Watson', 'Bleachers', 'The War on Drugs', 'The Antlers', 'Hot Chip', 'Rico & Sticks', 'Awolnation'"
Here's the double quote version, notice that double quotes must be escaped.
paste(shQuote(my.bands.list, type = "cmd"), collapse = ', ')
[1] "\"George Ezra\", \"Faith No More\", \"Above & Beyond\", \"Paloma Faith\", \"Gavin James\", \"DJ’s Waxfiend\", \"Jebroer\", \"Adje\", \"Pop Evil\", \"Jick munro & the amazing laserbeams\", \"Robbie Williams\", \"Avicii\", \"The Script\", \"Anouk\", \"Kensington\", \"Eagles of Death Metal\", \"Dotan\", \"The Wombats\", \"Selah Sue\", \"Shappard\", \"John Coffey\", \"Magic!\", \"Joost van Bellen\", \"East Camoran Folkcore\", \"Foo Fighters\", \"Pharrel Williams\", \"Sam Smith\", \"One Republic\", \"Rise Agianst\", \"De Jeugd van Tegenwoordig\", \"Counting Crows\", \"Fiddler’s Green\", \"Thyphoon\", \"Kovacs\", \"Kitty\", \"Daisy & Lewis\", \"Oscar and the Wolf\", \"Nick Mulvey\", \"Urbanus\", \"Willie Wartaal\", \"Doppelgang\", \"Ewert and the two dragons\", \"Pierce Brothers,Kovacs\", \"The Kendolls\", \"Stringcaster\", \"Sunday Sun\", \"Toy Dolls\", \"A$AP Rocky\", \"Ride\", \"Eskmo\", \"Temples\", \"The Pop Group\", \"Blank Mass\", \"Cairo Liberation Front\", \"Daniel Norgren\", \"Follakzoid\", \"Ghost Culture\", \"John Coffey\", \"Kevin Morby\", \"Kuenta I Tambu\", \"Marmozets\", \"Mourn\", \"Patten\", \"Sue The Night\", \"The Coathangers\", \"Tora\", \"Vessels\", \"The Libertines\", \"Noel Gallagher’s High Flying Brids\", \"Noel Gallagher\", \"AltJ\", \"Altj\", \"Royal Blood\", \"Sohn\", \"The Jesus & Mary Chain\", \"The Tallest Man On Earth\", \"Black Mountain\", \"Chet Faker\", \"Death Cab For Cutie\", \"Ear Sweatshirt\", \"Evian Christ\", \"Frist Aid Kit\", \"Future Islands\", \"Jonny Greenwood\", \"Mew\", \"Of Monsters And Men\", \"The Vaccines\", \"Ariel Pink\", \"Alvvays\", \"Wolf Alice\", \"Weval\", \"BADBADNOTGOOD\", \"Bass Drum Of Death\", \"Yak\", \"Daniel Romand\", \"Dan Dercon\", \"Eagulls\", \"Gengahr\", \"Fickle friends\", \"Steve Gunn\", \"Liima\", \"Hookworms\", \"Kate Tempest\", \"Kiasmds\", \"Strand of Oaks\", \"Little May \", \"Matthew E. White\", \"Metz\", \"Off!\", \"St. Paul\", \"St. Paul & The Broken Bones\", \"Pissed Jeans\", \"Pretty Vicious\", \"Reigning Sound\", \"Outfit\", \"Sunset Sons\", \"Waxahatchee\", \"Daniel Wilson\", \"Yung Lean\", \"Kindess\", \"Hinds,Damien Rice\", \"The War On Drugs\", \"Iggy Pop\", \"FKA Twigs\", \"Patti Smith And Her Band Perform Horses\", \"Flying Lotus\", \"Fat Freddy’s Drop\", \"Damian Jr Gong Marley\", \"Alabama Shakes\", \"The Gaslamp Killer\", \"Max Richter\", \"Motorpsycho\", \"Goat\", \"Songhoy Blues\", \"Andrew Brid\", \"Glass Animals\", \"King Gizzard & The Lizard Wizard\", \"Misun\", \"JD MCPherson\", \"Happyness\", \"Dolomite Minor\", \"Meridian Brothers\", \"Death From Above 1979\", \"Blaudzun\", \"Oscar And The Wolf\", \"Clark\", \"Ghost Poet\", \"Omar Souleyman\", \"Rhye\", \"Bejamin Booker\", \"Orkesta Mendoza\", \"Ganz,The Chemical Brothers\", \"Patrick Watson\", \"Bleachers\", \"The War on Drugs\", \"The Antlers\", \"Hot Chip\", \"Rico & Sticks\", \"Awolnation\""

Related

How can I get the key to increment when it is a string

I need to take someone’s age, and then outputs a key event from every year they have lived through.
dYearlyEvents = {
"1993": "Bill Clinton is inaugurated as the 42nd president.",
"1994": "The People's Republic of China gets its first connection to the Internet.",
"1995": "eBay is founded by Pierre Omidyar.",
"1996": "Murder of Tupac Shakur.",
"1997": "The first episode of Pokémon airs on TV Tokyo.",
"1998": "Death of Frank Sinatra.",
"1999": "The Columbine High School massacre in Colorado, United States, causes 15 deaths.",
"2000": "The Sony PlayStation 2 releases in Japan. ",
}
sBirthYear = (input("What year were you born in: \n"))
while True:
if sBirthYear in dYearlyEvents:
print(dYearlyEvents[sBirthYear])
sBirthYear += 1
This is what I tried but obviously as the input is a string it wont add a year every time it loops to print all events from 1993 to 2000 instead just prints 1993.

extract data from XML files - R

I'm new to extracting data from XML file. I'm trying to process the following an XML file using R XML packages. The information I want is in the attribute values.
I encounter two difficulties:
some attribute values exist in one node, but not in another node. For example, "DRP" has the information in the second but not in the first
some attributes has multiple values for an individual and i don't know how to link them to that individual. For example, "EmpHs" has multiple records for an individual (identified by indvlPK).
Ideally I want the output data has the structure similar to the following:
lastNm
firstNm
indvlPK
fromDt
orgNm
hasCustComp
GIGAX
JEFFREY
2783477
03/2004
GATEWAY FINANCIAL ADVISORS, INC
GIGAX
JEFFREY
2783477
03/2004
GFA IN
GIGAX
JEFFREY
2783477
01/2007
UNITED FIRST
HINSON
BRIAN
2783737
07/1996
LINCOLN FINANCIAL ADVISORS CORPORATION
Y
HINSON
BRIAN
2783737
07/1996
FIRST FINANCIAL GROUP
Y
Is there any way I can parse the data correctly? Thanks!
The code I used but didn't give me what I want:
doc <- "Test.xml"
ind <- xmlParse(doc)
xmltop = xmlRoot(ind)
temp1 <- data.frame(unlist(getNodeSet(xmltop,"//Info/#lastNm")))
temp2 <- data.frame(unlist(getNodeSet(xmltop,"//Info/#firstNm")))
temp3 <- data.frame(unlist(getNodeSet(xmltop,"//Info/#indvlPK")))
temp4 <- data.frame(unlist(getNodeSet(xmltop,"//EmpHs/#fromDt")))
temp5 <- data.frame(unlist(getNodeSet(xmltop,"//DRP/#hasCustComp")))
The data is here:
<?xml version="1.0" encoding="ISO-8859-1"?>
<IAPDIndividualReport GenOn="2021-03-29">
<Indvls>
<Indvl>
<Info lastNm="GIGAX" firstNm="JEFFREY" midNm="W" indvlPK="2783477" actvAGReg="Y" link="https://adviserinfo.sec.gov/individual/summary/2783477"/>
<OthrNms/>
<CrntEmps>
<CrntEmp orgNm="CAMBRIDGE INVESTMENT RESEARCH ADVISORS, INC." orgPK="134139" str1="1776 PLEASANT PLAIN RD." city="FAIRFIELD" state="IA" cntry="United States" postlCd="52556-8757">
<CrntRgstns>
<CrntRgstn regAuth="MO" regCat="RA" st="APPROVED" stDt="2010-09-09"/>
</CrntRgstns>
<BrnchOfLocs>
<BrnchOfLoc city="O&apos;FALLON" state="MO" cntry="United States"/>
</BrnchOfLocs>
</CrntEmp>
</CrntEmps>
<Exms>
<Exm exmCd="S63" exmNm="Uniform Securities Agent State Law Examination" exmDt="1996-08-20"/>
<Exm exmCd="S65" exmNm="Uniform Investment Adviser Law Examination" exmDt="1999-12-21"/>
</Exms>
<Dsgntns/>
<PrevRgstns>
<PrevRgstn orgNm="WOODBURY FINANCIAL SERVICES, INC." orgPK="421" regBeginDt="2009-01-05" regEndDt="2009-12-03">
<BrnchOfLocs>
<BrnchOfLoc city="OFALLON" state="MO"/>
<BrnchOfLoc city="OFALLON" state="MO"/>
<BrnchOfLoc city="DUBLIN" state="CA"/>
</BrnchOfLocs>
</PrevRgstn>
<PrevRgstn orgNm="FSC SECURITIES CORPORATION" orgPK="7461" regBeginDt="2004-10-29" regEndDt="2008-12-01">
<BrnchOfLocs>
<BrnchOfLoc city="O&apos;FALLON" state="MO"/>
<BrnchOfLoc city="ST. PETERS" state="MO"/>
</BrnchOfLocs>
</PrevRgstn>
<PrevRgstn orgNm="GATEWAY FINANCIAL ADVISORS, INC." orgPK="115025" regBeginDt="2004-11-11" regEndDt="2006-10-11">
<BrnchOfLocs>
<BrnchOfLoc city="ST. PETERS" state="MO"/>
</BrnchOfLocs>
</PrevRgstn>
</PrevRgstns>
<EmpHss>
<EmpHs fromDt="03/2004" orgNm="GATEWAY FINANCIAL ADVISORS, INC" city="OFALLON" state="MO"/>
<EmpHs fromDt="03/2004" orgNm="GFA INC" city="OFALLON" state="MO"/>
<EmpHs fromDt="01/2007" orgNm="UNITED FIRST" city="OFALLON" state="MO"/>
<EmpHs fromDt="09/2010" orgNm="CAMBRIDGE INVESTMENT RESEARCH ADVISORS, INC" city="FAIRFIELD" state="IA"/>
<EmpHs fromDt="09/2010" orgNm="CAMBRIDGE INVESTMENT RESEARCH, INC" city="FAIRFIELD" state="IA"/>
</EmpHss>
<OthrBuss>
<OthrBus desc="1)STONEBRIDGE WEALTH MANAGEMENT GROUP, 728 HAWK RUN DR, O&apos;FALLON, MO, 3/2008 AS INDEPENDENT INSURANCE AGENT FOR VARIOUS INDEPENDENT INSURANCE COMPANIES. INV REL - 40/MO - 20/TRADING. 2)UNITED FIRST FINANCIAL MORTGAGE SOFTWARE SALES. START 6/1/07, 10 HOURS PER MONTH, 5 DURING TRADING HOURS. NO OWNERSHIP INTEREST. 3)MORTGAGE STOP INC., 728 HAWK RUN DR., OFALLON, MO 63368. LOAN OFFICER PROCESSING LOAN APPS FOR CLIENTS. START 6/1/2002, 25 HOURS PER MONTH, 10 DURING TRADING HOURS. NO OWNERSHIP. 4)CIRA, 1776 PLEASANT PLAIN RD, FAIRFIELD, IA, AS ADVISORY REP OF A RIA. INV REL - 40 HR/WK - 40/TRADING. SEE EMPLOYMENT HISTORY FOR START DATE. 5) THE MORTGAGE SHOP, 355 MID RIVERS MALL DRIVE, STE E, ST. PETERS, MO 63376. MORTGAGE ORIGINATOR SINCE 01/01/99. NOT INVESTMENT RELATED. WORKS 60 HOURS PER MONTH, 20 OF WHICH ARE DURING TRADING HOURS. 6.365 PROPERTIES LLC, O&apos;FALLON, MO, 8/2018 AS OWNER OF LLC THAT BUYS, SELLS, & HOLDS REAL ESTATE. NIR - 20/MO - 0/TRADING. 7. BEST OFFER HOMES, LLC, 728 HAWK RUN DRIVE, O&apos;FALLON, MO, REAL ESTATE SALES/MORTGAGE ORIGINATION/ ACCOUNTING/FINANCIAL ACTIVITIES, 06/16/20, NIR, 20/MO- 0/TRADING 8. GIGAX WEALTH MANAGEMENT, 728 HAWK RUN DRIVE, OFALLON, MO, INDEPENDENT INSURANCE AGENT FOR VARIOUS INDEPENDENT INSURANCE COMPANIES,11/23/20, INV REL, 10 HR/WK- 10 TRADING HR."/>
</OthrBuss>
<DRPs/>
</Indvl>
<Indvl>
<Info lastNm="HINSON" firstNm="BRIAN" midNm="TROY" indvlPK="2783737" actvAGReg="Y" link="https://adviserinfo.sec.gov/individual/summary/2783737"/>
<OthrNms/>
<CrntEmps>
<CrntEmp orgNm="BRIDGEWORTH WEALTH MANAGEMENT" orgPK="164100" str1="101 25TH STREET NORTH" city="BIRMINGHAM" state="AL" cntry="United States" postlCd="35203">
<CrntRgstns>
<CrntRgstn regAuth="AL" regCat="RA" st="APPROVED" stDt="2015-05-12"/>
<CrntRgstn regAuth="TX" regCat="RA" st="APPROVED_RES" stDt="2015-05-01"/>
</CrntRgstns>
<BrnchOfLocs>
<BrnchOfLoc str1="400 MERIDIAN STREET" str2="SUITE 200" city="HUNTSVILLE" state="AL" cntry="United States" postlCd="35801"/>
<BrnchOfLoc str1="101 25TH STREET NORTH" city="BIRMINGHAM" state="AL" cntry="United States" postlCd="35203"/>
</BrnchOfLocs>
</CrntEmp>
</CrntEmps>
<Exms>
<Exm exmCd="S63" exmNm="Uniform Securities Agent State Law Examination" exmDt="1996-10-11"/>
</Exms>
<Dsgntns>
<Dsgntn dsgntnNm="Certified Financial Planner"/>
<Dsgntn dsgntnNm="Chartered Financial Consultant"/>
<Dsgntn dsgntnNm="Personal Financial Specialist"/>
</Dsgntns>
<PrevRgstns>
<PrevRgstn orgNm="LINCOLN FINANCIAL ADVISORS CORPORATION" orgPK="3978" regBeginDt="2000-04-25" regEndDt="2015-05-11">
<BrnchOfLocs>
<BrnchOfLoc city="HUNTSVILLE" state="AL"/>
<BrnchOfLoc city="HUNTSVILLE" state="AL"/>
</BrnchOfLocs>
</PrevRgstn>
</PrevRgstns>
<EmpHss>
<EmpHs fromDt="04/2015" orgNm="BRIDGEWORTH, LLC" city="HUNTSVILLE" state="AL"/>
<EmpHs fromDt="07/1996" toDt="04/2015" orgNm="LINCOLN FINANCIAL ADVISORS CORPORATION" city="HUNTSVILLE" state="AL"/>
<EmpHs fromDt="07/1996" toDt="04/2015" orgNm="FIRST FINANCIAL GROUP" city="BIRMINGHAM" state="AL"/>
<EmpHs fromDt="04/2015" orgNm="LPL FINANCIAL LLC" city="HUNTSVILLE" state="AL"/>
</EmpHss>
<OthrBuss>
<OthrBus desc="1) 04/30/2015: BRIDGEWORTH FINANCIAL, LLC - DBA FOR LPL BUSINESS (ENTITY FOR LPL BUSINESS) - INV REL - AT REPORTED BUSINESS LOCATIONS - START 01/01/2015 - 1% OF TIME SPENT 2) 04/30/2015: BRIDGEWORTH, LLC - INV REL - AT REPORTED BUSINESS LOCATION(S) - REGISTERED INVESTMENT ADVISOR HYBRID - START 01/2015 - 99% OF TIME SPENT. 3) 5/11/2015: NO BUSINESS NAME - INVESTMENT RELATED - AT REPORTED BUSINESS LOCATION(S) - NON-VARIABLE INSURANCE - STARTED 4/1/2015 - TIME SPENT 1% - LINES OF INSURANCE INCLUDE TERM, WHOLE, UNIVERSAL, LTC, DISABILITY. 4) 6/2/2017 - Bridgeworth Financial - Investment Related - At Reported Business Location(s) - DBA for LPL Business (entity for LPL business) - Started 04/30/2015 - 5 Hours Per Month/3 Hours During Securities Trading. 5) 5/8/2018 - Foster Properties Ltd - Not Investment Related - Home Based - Other-Family Business - Started 12/22/1997 - 1 Hours Per Month/0 Hours During Securities Trading - Handle the majority of business matters for this family business."/>
</OthrBuss>
<DRPs>
<DRP hasRegAction="N" hasCriminal="N" hasBankrupt="N" hasCivilJudc="N" hasBond="N" hasJudgment="N" hasInvstgn="N" hasCustComp="Y" hasTermination="N"/>
</DRPs>
</Indvl>
</Indvls>
</IAPDIndividualReport>

Merging similar descriptions in bank statement output

Here is a sample part of a bank statement:
Description<-c(
"EXXONMOBIL 46344172 "
"EXXONMOBIL 97142239 "
"EXXONMOBIL 97523322 "
"EXXONMOBIL 99123183 "
"JIMMY JOHNS - 1236 "
"JIMMY JOHNS - 2453 "
"JIMMY JOHNS # 95612 "
"KWIK FILL 212 "
"KWIK TRIP 24500001231 "
"KWIK TRIP 32100002342 "
"KWIK TRIP 67200003453 "
"MCDONALD'S F11123 "
"MCDONALD'S F11234 "
"MCDONALD'S F25345 "
"MCDONALD'S F5349 "
)
Debit<-as.numeric(c(
"25.98",
"24.54",
"29.59",
"31.85",
"7.61",
"17.82",
"10.58",
"26.5",
"22.48",
"146.62",
"52.51",
"2.57",
"7.77",
"9.59",
"11.85"
))
df<-data.frame(Description,Debit)
with the following output:
Description Debit
EXXONMOBIL 46946182 25.98
EXXONMOBIL 97302509 24.54
EXXONMOBIL 97585822 29.59
EXXONMOBIL 99374183 31.85
JIMMY JOHNS - 1476 7.61
JIMMY JOHNS - 2763 17.82
JIMMY JOHNS # 90012 10.58
KWIK FILL 228 26.5
KWIK TRIP 24500002451 22.48
KWIK TRIP 32100003210 146.62
KWIK TRIP 67200006726 52.51
MCDONALD'S F11780 2.57
MCDONALD'S F11883 7.77
MCDONALD'S F25398 9.59
MCDONALD'S F4789 11.85
I was wondernig how would it be possible to aggregate the results by Description so that the unique codes are removed and I get summarized amount of expenses by each company like Exxonmobil, Jimmy Johns, etc.. Not sure if the best way if to eliminate everything after a blank space, eliminate all the numeric characters, or (in my mind could be the best one) get rid of all numeric and special characters and keep only the letters?
In any way the desired output would be something like this:
Description Debit
EXXONMOBIL 111.96
JIMMY JOHNS 36.01
KWIK FILL 26.5
KWIK TRIP 221.61
MCDONALD'S 31.78
Any suggestions?
This would be fairly simple to do in REGEX.
E.g.
EXXONMOBIL.* (\d*.\d*)
You can see it working here...
Once you have those values in a group you can use whatever language to sum together values or change out which root your searching for.

How to split Character Columns into multiple columns and then into binary in R?

I got a data set with around 4000 observations:
It looks like this format:
View(transaction)
CustomerID Description
12346 MEDIUM CERAMIC TOP STORAGE JAR
12347 c("BLACK CANDLEABRA HOLDER","AIRLINE BAG VINTAGE JET SET BROWN", ...)
12348 c("72 SWEETHEART FAIRY CAKE CASES","60 CAKE CASES DOLLY GIRL DESIGN","PACK OF 72 SKULL CAKE CASES",...)
12349 c("PARISIENNE CURIO CABINET","SWEETHEART WALL TIDY",...)
12350 c("CHOCOLATE THIS WAY METAL SIGN","RETRO MOD TRAY",...)
12352 c("CERAMIC CAKE STAND + HANGING CAKES", WOODEN HAPPY BIRTHDAY GARLAND, ...)
I want it in the first step that it looks like this:
CustomerID PRODUCT_1 PRODUCT_2 PRODUCT_N
12346 MEDIUM CERAMIC TOP STORAGE JAR
12347 BLACK CANDLEABRA HOLDER AIRLINE BAG VINTAGE JET SET BROWN ...
12348 72 SWEETHEART FAIRY CAKE CASES" 60 CAKE CASES DOLLY GIRL DESIGN PACK OF 72 SKULL CAKE CASES
12349 PARISIENNE CURIO CABINET. SWEETHEART WALL TIDY ...
12350 CHOCOLATE THIS WAY METAL SIGN RETRO MOD TRAY ...
12352 CERAMIC CAKE STAND + HANGING CAKES WOODEN HAPPY BIRTHDAY GARLAND ...
I tried it with cSplit, but I don't know how to do this with this Dataset.
In the last step I would like to get a binary Matrix like this:
MEDIUM CERAMIC TOP STORAGE JAR BLACK CANDLEABRA HOLDER AIRLINE BAG VINTAGE JET SET BROWN
12346 1 0 0
12347 0 1 1
12348 0 0 0
12349 0 0 0
12350 0 0 0
12352 0 0 0
It would help me a lot if anyone can solve this problem.
Many thanks,
Marre
Edit:
dput(droplevels(head(transactions)))
structure(list(CustomerID = c(12346, 12347, 12348, 12349, 12350,
12352), Description = structure(list(`0001` = "MEDIUM CERAMIC TOP STORAGE JAR",
`0002` = c("BLACK CANDELABRA T-LIGHT HOLDER", "AIRLINE BAG VINTAGE JET SET BROWN",
"COLOUR GLASS. STAR T-LIGHT HOLDER", "MINI PAINT SET VINTAGE ",
"CLEAR DRAWER KNOB ACRYLIC EDWARDIAN", "PINK DRAWER KNOB ACRYLIC EDWARDIAN",
"GREEN DRAWER KNOB ACRYLIC EDWARDIAN", "RED DRAWER KNOB ACRYLIC EDWARDIAN",
"PURPLE DRAWERKNOB ACRYLIC EDWARDIAN", "BLUE DRAWER KNOB ACRYLIC EDWARDIAN",
"ALARM CLOCK BAKELIKE CHOCOLATE", "ALARM CLOCK BAKELIKE GREEN",
"ALARM CLOCK BAKELIKE RED ", "ALARM CLOCK BAKELIKE PINK",
"ALARM CLOCK BAKELIKE ORANGE", "FOUR HOOK WHITE LOVEBIRDS",
"BLACK GRAND BAROQUE PHOTO FRAME", "BATHROOM METAL SIGN ",
"LARGE HEART MEASURING SPOONS", "BOX OF 6 ASSORTED COLOUR TEASPOONS",
"BLUE 3 PIECE POLKADOT CUTLERY SET", "RED 3 PIECE RETROSPOT CUTLERY SET",
"PINK 3 PIECE POLKADOT CUTLERY SET", "EMERGENCY FIRST AID TIN ",
"SET OF 2 TINS VINTAGE BATHROOM ", "SET/3 DECOUPAGE STACKING TINS",
"BOOM BOX SPEAKER BOYS", "RED TOADSTOOL LED NIGHT LIGHT",
"3D DOG PICTURE PLAYING CARDS", "BLACK EAR MUFF HEADPHONES",
"CAMOUFLAGE EAR MUFF HEADPHONES", "PINK NEW BAROQUECANDLESTICK CANDLE",
"BLUE NEW BAROQUE CANDLESTICK CANDLE", "BLACK CANDELABRA T-LIGHT HOLDER",
"WOODLAND CHARLOTTE BAG", "AIRLINE BAG VINTAGE JET SET BROWN",
"AIRLINE BAG VINTAGE JET SET WHITE", "SANDWICH BATH SPONGE",
"ALARM CLOCK BAKELIKE CHOCOLATE", "ALARM CLOCK BAKELIKE GREEN",
"ALARM CLOCK BAKELIKE RED ", "ALARM CLOCK BAKELIKE PINK",
"ALARM CLOCK BAKELIKE ORANGE", "SMALL HEART MEASURING SPOONS",
"72 SWEETHEART FAIRY CAKE CASES", "60 TEATIME FAIRY CAKE CASES",
"PACK OF 60 MUSHROOM CAKE CASES", "PACK OF 60 SPACEBOY CAKE CASES",
"TEA TIME OVEN GLOVE", "RED RETROSPOT OVEN GLOVE ", "RED RETROSPOT OVEN GLOVE DOUBLE",
"SET/2 RED RETROSPOT TEA TOWELS ", "REGENCY CAKESTAND 3 TIER",
"BOX OF 6 ASSORTED COLOUR TEASPOONS", "MINI LADLE LOVE HEART RED ",
"CHOCOLATE CALCULATOR", "TOOTHPASTE TUBE PEN", "SET OF 2 TINS VINTAGE BATHROOM ",
"RED TOADSTOOL LED NIGHT LIGHT", "3D DOG PICTURE PLAYING CARDS",
"AIRLINE BAG VINTAGE JET SET WHITE", "AIRLINE BAG VINTAGE JET SET RED",
"AIRLINE BAG VINTAGE TOKYO 78", "AIRLINE BAG VINTAGE JET SET BROWN",
"RED RETROSPOT PURSE ", "ICE CREAM SUNDAE LIP GLOSS", "VINTAGE HEADS AND TAILS CARD GAME ",
"HOLIDAY FUN LUDO", "TREASURE ISLAND BOOK BOX", "WATERING CAN PINK BUNNY",
"RED DRAWER KNOB ACRYLIC EDWARDIAN", "LARGE HEART MEASURING SPOONS",
"SMALL HEART MEASURING SPOONS", "PACK OF 60 DINOSAUR CAKE CASES",
"RED RETROSPOT OVEN GLOVE DOUBLE", "REGENCY CAKESTAND 3 TIER",
"ROSES REGENCY TEACUP AND SAUCER ", "RED TOADSTOOL LED NIGHT LIGHT",
"MINI PAINT SET VINTAGE ", "3D SHEET OF DOG STICKERS", "3D SHEET OF CAT STICKERS",
"SMALL FOLDING SCISSOR(POINTED EDGE)", "GIFT BAG PSYCHEDELIC APPLES",
"SET OF 2 TINS VINTAGE BATHROOM ", "RABBIT NIGHT LIGHT",
"REGENCY TEA STRAINER", "REGENCY TEA PLATE GREEN ", "REGENCY TEA PLATE PINK",
"REGENCY TEA PLATE ROSES ", "REGENCY TEAPOT ROSES ", "REGENCY SUGAR BOWL GREEN",
"REGENCY MILK JUG PINK ", "AIRLINE BAG VINTAGE TOKYO 78",
"AIRLINE BAG VINTAGE JET SET BROWN", "VICTORIAN SEWING KIT",
"NAMASTE SWAGAT INCENSE", "TRIPLE HOOK ANTIQUE IVORY ROSE",
"SMALL HEART MEASURING SPOONS", "3D DOG PICTURE PLAYING CARDS",
"FEATHER PEN,COAL BLACK", "ALARM CLOCK BAKELIKE RED ", "ALARM CLOCK BAKELIKE CHOCOLATE",
"SET OF 60 VINTAGE LEAF CAKE CASES ", "SET 40 HEART SHAPE PETIT FOUR CASES",
"AIRLINE BAG VINTAGE JET SET BROWN", "AIRLINE BAG VINTAGE JET SET RED",
"AIRLINE BAG VINTAGE JET SET WHITE", "AIRLINE BAG VINTAGE TOKYO 78",
"AIRLINE BAG VINTAGE WORLD CHAMPION ", "WOODLAND DESIGN COTTON TOTE BAG",
"WOODLAND CHARLOTTE BAG", "ALARM CLOCK BAKELIKE RED ", "TRIPLE HOOK ANTIQUE IVORY ROSE",
"SINGLE ANTIQUE ROSE HOOK IVORY", "TEA TIME OVEN GLOVE",
"72 SWEETHEART FAIRY CAKE CASES", "60 TEATIME FAIRY CAKE CASES",
"PACK OF 60 DINOSAUR CAKE CASES", "REGENCY CAKESTAND 3 TIER",
"REGENCY MILK JUG PINK ", "3D DOG PICTURE PLAYING CARDS",
"REVOLVER WOODEN RULER ", "VINTAGE HEADS AND TAILS CARD GAME ",
"RED REFECTORY CLOCK ", "MINI LIGHTS WOODLAND MUSHROOMS",
"PINK GOOSE FEATHER TREE 60CM", "MADRAS NOTEBOOK MEDIUM",
"AIRLINE BAG VINTAGE WORLD CHAMPION ", "AIRLINE BAG VINTAGE JET SET BROWN",
"AIRLINE BAG VINTAGE TOKYO 78", "AIRLINE BAG VINTAGE JET SET RED",
"BIRDCAGE DECORATION TEALIGHT HOLDER", "CHRISTMAS METAL TAGS ASSORTED ",
"REGENCY CAKESTAND 3 TIER", "REGENCY TEAPOT ROSES ", "TEA TIME DES TEA COSY",
"TEA TIME KITCHEN APRON", "TEA TIME OVEN GLOVE", "PINK REGENCY TEACUP AND SAUCER",
"GREEN REGENCY TEACUP AND SAUCER", "3D DOG PICTURE PLAYING CARDS",
"RABBIT NIGHT LIGHT", "RED TOADSTOOL LED NIGHT LIGHT", "TREASURE ISLAND BOOK BOX",
"VINTAGE HEADS AND TAILS CARD GAME ", "MINI PLAYING CARDS DOLLY GIRL ",
"MINI PLAYING CARDS SPACEBOY ", "PLAYING CARDS KEEP CALM & CARRY ON",
"REVOLVER WOODEN RULER ", "WOODEN SCHOOL COLOURING SET",
"MINI PAINT SET VINTAGE ", "TRADITIONAL KNITTING NANCY",
"TRIPLE HOOK ANTIQUE IVORY ROSE", "PANTRY HOOK SPATULA",
"PANTRY HOOK BALLOON WHISK ", "PANTRY HOOK TEA STRAINER ",
"ROSES REGENCY TEACUP AND SAUCER ", "ALARM CLOCK BAKELIKE CHOCOLATE",
"ALARM CLOCK BAKELIKE PINK", "ALARM CLOCK BAKELIKE GREEN",
"ALARM CLOCK BAKELIKE RED ", "PACK OF 60 MUSHROOM CAKE CASES",
"PACK OF 60 SPACEBOY CAKE CASES", "SET OF 60 VINTAGE LEAF CAKE CASES ",
"60 TEATIME FAIRY CAKE CASES", "72 SWEETHEART FAIRY CAKE CASES",
"SMALL HEART MEASURING SPOONS", "LARGE HEART MEASURING SPOONS",
"WOODLAND CHARLOTTE BAG", "REGENCY TEA STRAINER", "FOOD CONTAINER SET 3 LOVE HEART ",
"CLASSIC CHROME BICYCLE BELL ", "BICYCLE PUNCTURE REPAIR KIT ",
"BOOM BOX SPEAKER BOYS", "PINK NEW BAROQUECANDLESTICK CANDLE",
"RED TOADSTOOL LED NIGHT LIGHT", "RABBIT NIGHT LIGHT", "WOODLAND CHARLOTTE BAG",
"PINK GOOSE FEATHER TREE 60CM", "CHRISTMAS TABLE SILVER CANDLE SPIKE",
"MINI PLAYING CARDS SPACEBOY ", "MINI PLAYING CARDS DOLLY GIRL "
), `0003` = c("72 SWEETHEART FAIRY CAKE CASES", "60 CAKE CASES DOLLY GIRL DESIGN",
"60 TEATIME FAIRY CAKE CASES", "60 TEATIME FAIRY CAKE CASES",
"PACK OF 72 SKULL CAKE CASES", "PACK OF 72 SKULL CAKE CASES",
"PACK OF 12 LONDON TISSUES ", "PACK OF 12 WOODLAND TISSUES ",
"PACK OF 12 SUKI TISSUES ", "SWEETIES STICKERS", "SET OF 72 SKULL PAPER DOILIES",
"SET OF 72 PINK HEART PAPER DOILIES", "60 CAKE CASES VINTAGE CHRISTMAS",
"60 CAKE CASES VINTAGE CHRISTMAS", "PACK OF 60 PINK PAISLEY CAKE CASES",
"PACK OF 60 PINK PAISLEY CAKE CASES", "POSTAGE", "PACK OF 12 RED RETROSPOT TISSUES ",
"PACK OF 12 HEARTS DESIGN TISSUES ", "MULTI HEARTS STICKERS",
"PACK OF 12 BLUE PAISLEY TISSUES ", "PACK OF 12 SKULL TISSUES",
"POSTAGE", "DOUGHNUT LIP GLOSS ", "ICE CREAM PEN LIP GLOSS ",
"ICE CREAM SUNDAE LIP GLOSS", "SET OF 9 BLACK SKULL BALLOONS",
"POSTAGE", "DOUGHNUT LIP GLOSS ", "ICE CREAM PEN LIP GLOSS ",
"POSTAGE"), `0004` = c("PARISIENNE CURIO CABINET", "SWEETHEART WALL TIDY ",
"PINK HEART SHAPE LOVE BUCKET ", "GINGHAM HEART DOORSTOP RED",
"RED HEART SHAPE LOVE BUCKET ", "FOOD CONTAINER SET 3 LOVE HEART ",
"LARGE HEART MEASURING SPOONS", "DOORMAT HEARTS", "HANGING HEART JAR T-LIGHT HOLDER",
"BROCANTE SHELF WITH HOOKS", "PLASTERS IN TIN VINTAGE PAISLEY ",
"PANTRY MAGNETIC SHOPPING LIST", "RECIPE BOX PANTRY YELLOW DESIGN",
"SET OF 3 CAKE TINS PANTRY DESIGN ", "JAM MAKING SET WITH JARS",
"SET OF 6 SPICE TINS PANTRY DESIGN", "PANTRY CHOPPING BOARD",
"DOORMAT WELCOME TO OUR HOME", "16 PIECE CUTLERY SET PANTRY DESIGN",
"SMALL WHITE RETROSPOT MUG IN BOX ", "BLACK/BLUE POLKADOT UMBRELLA",
"20 DOLLY PEGS RETROSPOT", "SET/4 WHITE RETRO STORAGE CUBES ",
"REGENCY CAKESTAND 3 TIER", "SET/5 RED RETROSPOT LID GLASS BOWLS",
"DOORMAT RED RETROSPOT", "SET/6 RED SPOTTY PAPER CUPS", "RED RETROSPOT SMALL MILK JUG",
"RED RETROSPOT SUGAR JAM BOWL", "RETROSPOT LARGE MILK JUG",
"SMALL RED RETROSPOT MUG IN BOX ", "RAIN PONCHO RETROSPOT",
"RED RETROSPOT UMBRELLA", "PLASTERS IN TIN SKULLS", "GLASS SONGBIRD STORAGE JAR",
"SET OF 12 FAIRY CAKE BAKING CASES", "SET OF 6 TEA TIME BAKING CASES",
"SET OF 6 SNACK LOAF BAKING CASES", "WRAP RED VINTAGE DOILY",
"SET OF 12 MINI LOAF BAKING CASES", "STORAGE TIN VINTAGE DOILY ",
"SET OF 4 KNICK KNACK TINS DOILY ", "DOORMAT VINTAGE LEAF",
"ROUND SNACK BOXES SET OF4 WOODLAND ", "PLASTERS IN TIN WOODLAND ANIMALS",
"PLASTERS IN TIN STRONGMAN", "RETROSPOT PARTY BAG + STICKER SET",
"VINTAGE DOILY TRAVEL SEWING KIT", "VINTAGE DOILY DELUXE SEWING KIT ",
"CLASSIC CHROME BICYCLE BELL ", "EMBROIDERED RIBBON REEL SALLY ",
"PAINTED METAL PEARS ASSORTED", "WRAP RED APPLES ", "CHRISTMAS RETROSPOT ANGEL WOOD",
"SET OF 3 WOODEN HEART DECORATIONS", "HEART T-LIGHT HOLDER WILLIE WINKIE",
"HAND WARMER RED LOVE HEART", "ZINC FOLKART SLEIGH BELLS",
"PLASTERS IN TIN CIRCUS PARADE ", "ENGLISH ROSE SPIRIT LEVEL ",
"SET OF 10 LED DOLLY LIGHTS", "FRENCH ENAMEL CANDLEHOLDER",
"GROW YOUR OWN BASIL IN ENAMEL MUG", "ENAMEL WATERING CAN CREAM",
"DOORMAT ENGLISH ROSE ", "CERAMIC STRAWBERRY DESIGN MUG",
"SWEETHEART CERAMIC TRINKET BOX", "STRAWBERRY CERAMIC TRINKET POT",
"PINK DOUGHNUT TRINKET POT ", "CERAMIC CAKE DESIGN SPOTTED MUG",
"TEA TIME TEAPOT IN GIFT BOX", "DOORMAT FAIRY CAKE", "POSTAGE"
), `0005` = c("CHOCOLATE THIS WAY METAL SIGN", "METAL SIGN NEIGHBOURHOOD WITCH ",
"RETRO MOD TRAY", "RETRO PLASTIC ELEPHANT TRAY", "TEA BAG PLATE RED RETROSPOT",
"PINK/PURPLE RETRO RADIO", "PLASTERS IN TIN SPACEBOY", "PLASTERS IN TIN VINTAGE PAISLEY ",
"CHOCOLATE CALCULATOR", "RED HARMONICA IN BOX ", "4 TRADITIONAL SPINNING TOPS",
"BATHROOM METAL SIGN ", "POSTAGE", "UNION JACK FLAG PASSPORT COVER ",
"UNION JACK FLAG LUGGAGE TAG", "BLUE POLKADOT LUGGAGE TAG ",
"BLUE POLKADOT PASSPORT COVER"), `0006` = c("WOODEN HAPPY BIRTHDAY GARLAND",
"PINK DOUGHNUT TRINKET POT ", "STRAWBERRY CERAMIC TRINKET BOX",
"CERAMIC STRAWBERRY CAKE MONEY BANK", "WOODEN OWLS LIGHT GARLAND ",
"REGENCY CAKESTAND 3 TIER", "DELUXE SEWING KIT ", "WELCOME WOODEN BLOCK LETTERS",
"LOVE BUILDING BLOCK WORD", "BATH BUILDING BLOCK WORD", "HOME BUILDING BLOCK WORD",
"CAT BOWL VINTAGE CREAM", "BIG DOUGHNUT FRIDGE MAGNETS",
"DOLLY GIRL LUNCH BOX", "LIGHT GARLAND BUTTERFILES PINK",
"POSTAGE", "DELUXE SEWING KIT ", "PINK HEART SHAPE EGG FRYING PAN",
"BAKING SET 9 PIECE RETROSPOT ", "VINTAGE CREAM DOG FOOD CONTAINER",
"Manual", "Manual", "Manual", "CERAMIC HEART FAIRY CAKE MONEY BANK",
"CERAMIC CAKE DESIGN SPOTTED MUG", "BLUE HARMONICA IN BOX ",
"PINK DOG BOWL", "PINK HEART SHAPE EGG FRYING PAN", "LANTERN CREAM GAZEBO ",
"METAL SIGN TAKE IT OR LEAVE IT ", "POSTAGE", "PINK HEART SHAPE EGG FRYING PAN",
"CERAMIC CAKE DESIGN SPOTTED MUG", "LANTERN CREAM GAZEBO ",
"PINK DOG BOWL", "CERAMIC HEART FAIRY CAKE MONEY BANK", "METAL SIGN TAKE IT OR LEAVE IT ",
"BLUE HARMONICA IN BOX ", "ANTIQUE GLASS PEDESTAL BOWL",
"PANTRY MAGNETIC SHOPPING LIST", "PANTRY SCRUBBING BRUSH",
"SET OF 3 REGENCY CAKE TINS", "SMALL GLASS HEART TRINKET POT",
"DOORMAT WELCOME TO OUR HOME", "SET OF 4 PANTRY JELLY MOULDS",
"PANTRY WASHING UP BRUSH", "BAKING SET SPACEBOY DESIGN",
"IVORY KITCHEN SCALES", "SET OF 3 CAKE TINS PANTRY DESIGN ",
"REGENCY CAKESTAND 3 TIER", "WOODEN OWLS LIGHT GARLAND ",
"LIGHT GARLAND BUTTERFILES PINK", "FAIRY CAKE BIRTHDAY CANDLE SET",
"SPOTTY BUNTING", "SET OF 4 ENGLISH ROSE COASTERS", "POSTAGE",
"OPEN CLOSED METAL SIGN", "SET OF 6 SPICE TINS PANTRY DESIGN",
"SET OF 3 REGENCY CAKE TINS", "RED TOADSTOOL LED NIGHT LIGHT",
"CHILDS BREAKFAST SET DOLLY GIRL ", "CHILDS BREAKFAST SET SPACEBOY ",
"SET OF 3 CAKE TINS PANTRY DESIGN ", "SET OF TEA COFFEE SUGAR TINS PANTRY",
"LOVE BUILDING BLOCK WORD", "HOLIDAY FUN LUDO", "BATH BUILDING BLOCK WORD",
"WOODEN OWLS LIGHT GARLAND ", "LIGHT GARLAND BUTTERFILES PINK",
"POSTAGE", "PETIT TRAY CHIC", "PANTRY ROLLING PIN", "PANTRY PASTRY BRUSH",
"WOODLAND BUNNIES LOLLY MAKERS", "PINK BABY BUNTING", "MINT KITCHEN SCALES",
"SET 12 COLOUR PENCILS SPACEBOY ", "ZINC HEART FLOWER T-LIGHT HOLDER",
"VICTORIAN GLASS HANGING T-LIGHT", "IVORY KITCHEN SCALES",
"GLASS BON BON JAR", "BLUE STRIPE CERAMIC DRAWER KNOB", "SET 12 COLOUR PENCILS DOLLY GIRL ",
"CHILDS BREAKFAST SET DOLLY GIRL ", "POSTAGE")), .Names = c("0001",
"0002", "0003", "0004", "0005", "0006"))), .Names = c("CustomerID",
"Description"), row.names = c(NA, 6L), class = "data.frame")
We can try with unnest to make the elements of list column a row, then spread it to wide format after creating a sequence column ('ind')
library(tidyr)
library(dplyr)
res <- unnest(transactions, Description) %>%
group_by(CustomerID) %>%
mutate(ind = paste0("PRODUCT", row_number())) %>%
spread(ind, Description)
and to get the second part of the question, use mtabulate from qdapTools
library(qdapTools)
res2 <- setNames(as.data.frame(t(res[-1])), res[[1]]) %>%
mtabulate

change different columns using colClasses in a single attempt in R

I have a dataset in csv as follows-
Sample of the data is as well pasted below
Now I have columns like Transaction.Data which is Date type but read.csv is expecting real , again Transaction is String, which I want to convert to Dr.(0) and Cr.(1) , and I have Amount which has comma in-between, which I want to change to Integer or vector with decimal so that I could plot.
To convert Cr.(1) and Dr.(0) , I found the solution from my previous question as-'
setClass("CrDr")
setAs("character", "CrDr", function(from) c(Cr.=1,Dr.=0)[from])
So now I have 3 things to do while reading the csv-
Transaction.data <- date
Transaction <- Dr.(0) Cr.(1)
Amount/Balance <- numeric
How to achieve these many kind of changes in a single attempt.
Data Sample
Transaction Date Remarks Transaction Amount Balance
26/05/2014 ATM/CASH WDL/26-05-14/18:12:12/0 Dr. 3,000.00 1,11,216.17
26/05/2014 ATD/Auto Debit CC5xx3009 Dr. 3,953.22 1,14,216.17
22/05/2014 TRFR FROM:SRI GANESH INFRATECH &SOFTWARE PVT LTD Cr. 36,000.00 1,18,169.39
21/05/2014 BIL/000593351901/priyanka/VODAESP_MICI335 Dr. 555 82,169.39
17/05/2014 IPS/SPENCERS RE/20140517124555/0 Dr. 514 82,724.39
12/5/2014 BIL/000589207330/Kolkataairfare/INDIGO_MICI3346 Dr. 7,617.00 83,238.39
6/5/2014 BIL/000586940549/Mumma#May/NSP Dr. 1,10,000.00 90,855.39
3/5/2014 BIL/000585385115/airtel#bb/AIRTEL_MICI3338 Dr. 797 2,00,855.39
3/5/2014 IPS/SPENCERS RE/20140503112817/0 Dr. 328 2,01,652.39
1/5/2014 NEFT-AXMB141215740194-ABHISHEK CHOUDHARY-may month Cr. 1,00,000.00 2,01,980.39
29/04/2014 TRFR FROM:SRI GANESH INFRATECH & SOFTWARE PVT LTD Cr. 12,000.00 1,01,980.39
26/04/2014 ATM/CASH WDL/26-04-14/21:20:31/0 Dr. 1,000.00 89,980.39
25/04/2014 ATD/Auto Debit CC5xx3009 Dr. 897 90,980.39
19/04/2014 VIN/Tata_Sky_DT/20140419180921/0 Dr. 351 91,877.39
10/4/2014 BY CASH - BHOPAL Cr. 3,000.00 92,228.39
31/03/2014 BIL/000570396248/Mumma#Mar/NSP Dr. 1,50,000.00 89,228.39
31/03/2014 NEFT-AXMB140902244145-ABHISHEK CHOUDHARY- Cr. 30,000.00 2,39,228.39

Resources