change different columns using colClasses in a single attempt in R - 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

Related

R extract specific word after keyword

How do I extract a specific word after keyword in R.
I have the following input text which contains details about policy. I need to extract specific words value like FirstName , SurName , FatherName and dob.
input.txt
In Case of unit linked plan, Investment risk in Investment Portfolio is borne by the policyholder.
ly
c I ROPOSAL FORM z
Insurance
Proposal Form Number: 342525 PF 42242
Advisor Coe aranch Code 2
Ff roanumber =F SSOS™S™~™S~S rancid ate = |
IBR. Code S535353424
re GFN ——
INSTRUCTION FOR FILLING THES APPLICATION FORM ; 1. Compiets the proocsal form in CAPITAL LETTERS using = Black Ball Point P]n. 2. Sless= mark your selection by marking “X" insides the
Boe. 3. Slnsse bases 2 Blank soece after eect word, letter or initial 4. Slssse write "MA" for questions whic are not apolicatie. 5.00 NOT USE the Sor") to identify your initial or seperate the sddressiiine.
6. Sulmissson of age proof ie mandatory along wall Ge propel fonm.
IMPORTANT INSTRUCTIONS WITH REGARD TO DISCLOSURE OF INFORMATION: Inturance it a contract of UTMOST GOOD FAITH and itis required by disclose all material and nelevant
fach: complebehy, DO) NOT suppress any fac: in response by the questions in the priposal form. FAILURE TO PROVIDE COMPLETE AND ACCURATE INFORMATION OR
MISREPRESENTATION OF THE FACTS COULD DECLARE THES POLICY CONTRACT NULL AND VOID AFTER PAYMENT OF SURRENDER VALUE, IF ANY, SUBJECT TO SECTION 45 OF
INSURANCE ACT, 1998 As AMENDED FROM TIME TO TIME,
Section I - Details of the Life to be Assured
1. Tite E-] Mr. LJ Mrs. LJ Miss [J Or. LJ Others (Specify)
2. FirstName PETER PAUL
3. Surname T
44. Father's Name
46, Mother's Name ERIKA RESWE D
5. Date of Birth 13/02/1990 6, Gender E] Male ] Female
7. Age Proof L] School Certificate [] Driving License [] Passport {Birth Certificate E"] PAN Card
3, Marital Status D) Single EF] Married 0 Widower) 0 Civorcee
9, Spouse Name ERISEWQ FR
10. Maiden Name
iL. Nationality -] Resident Indian National [J Non Resident Indian (MRI) L] Others (Specify)
12, Education J Postgraduate / Doctorate Ee) Graduate [] 12thstd. Pass [J 10thstd. Pass [J Below 10th std.
OO Dliterate / Uneducated CJ Others (Specify)
13. Address For No 7¥%a vaigai street Flower
Communication Nagar selaiyur
Landmark
City Salem
Pin Code BO00 73: State TAMIL NADU
Address proof [] Passport ([] Driving License [] Voter ID [] Bank Statement [] Utility Bill G4 Others (Specify) Aadhaar Card
14, Permanent No 7¥a vaigai street Flower
Address :
Nagar selaiyur
Landmark
City Salem
Pin Code 5353535 state (TAMIL NADU
Address proof CJ] Passport [9 DrivingLicense [J Voter ID [ Bank Statement [ Utility Bill B] Others (Specify) Aadhaar Card
15. Contact Details Mobile 424242424 Phone (Home)
Office / Business
E-mail fdgrgtr13#yahoo.com
Preferred mode: ((] Letter EF) E-Mail
Preferred Language for Letter {other than English): [] Hindi [] Kannada [-] Tamil J Telugu C] Malayalam C) Gujarati
Bengali GOriya =D] Marathi
16. Occupation CL] Salaried-Govt /PSU ( Salaried-other [9 Self Employed Professional [J Aagriculturist {Farmer [Part Time Business
LJ Retired ] Landlord J Student (current Std) -] Others (Specify) Salaried - MNC
17. Full Name of the Capio software
Employers Businnes/
School/College
18, Designation & Exact nature of Work / Business Manager
19. AnnualIncomein 1,200,000.00 20. Annual Income of Husband / Father = 1,500,000.00
Figures (%) (for female and minor lives)
21. Exact nature of work / business of Husband / Father for female and minor lives Government Employee
Page 10fé
The below code works for me but the problem is if line order changes everything get changed. Is there a way to extract keyword value irrespective of line order. ?
Current Code
path <- getwd()
my_txt <- readLines(paste(path, "/input.txt", sep = ""))
fName <- sub('.*FirstName', '', my_txt[7])
SName <- sub('.*Surname', '', my_txt[8])
FatherNm <- sub(".*Father's Name", '', my_txt[9])
dob <- sub("6, Gender.*", '',sub(".*Date of Birth", '', my_txt[11]))
You can combine the text together as one string and extract the values based on pattern in the data. This approach will work irrespective of the line number in the data provided the pattern in the data is always valid for all the files.
my_txt <- readLines(paste(path, "/input.txt", sep = ""))
#Collapse data in one string
text <- paste0(my_txt, collapse = '\n')
#Extract text after FirstName till '\n'
fName <- sub('.*FirstName (.*?)\n.*', '\\1', text)
fName
#[1] "John Woo"
#Extract text after Surname till '\n'
SName <- sub('.*Surname (.*?)\n.*', '\\1', text)
SName
#[1] "T"
#Extract text after Father's Name till '\n'
FatherNm <- sub(".*Father's Name (.*?)\n.*", '\\1', text)
FatherNm
#[1] "Bill Woo"
#Extract numbers which come after Date of Birth.
dob <- sub(".*Date of Birth (\\d+/\\d+/\\d+).*", '\\1', text)
dob
#[1] "13/07/1970"

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.

shyquote does not work! What to do?

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\""

Row count for a column

In my subreport I want do display for eg.
Number of clients born in 1972: 34
So in the database I have a list of their birth years
How can I display this number in a field?
Here is a Sample of the data:
<Born> <Name> <BleBle>
1981 Mnr EH Van Niekerk 9517
1982 MEV A BELL 9520
1972 Mnr GI van der Westhuize 9517
1987 Mnr A Juyn 9517
1983 Mev MJC Prinsloo 9513
1972 Mnr WA Van Rensburg 9517
1989 Kmdt EL Van Der Colff 9514
1972 Mnr JS Jansen Van Vuuren 9517
So if this was all the data the output would have to be
Number of clients born in 1972: 3
Create a variable BORN_IN_1972.
Set its "Variable class" to java.lang.Integer.
Set "Calculation" to "Count".
Set "Variable Expression" to $F{Born}.
Set "Initial Value Expression" to 0.
Than add "Summary" band to your report. And put static text "Number of clients born in 1972:" and text field "$V{BORN_IN_1972}" into it.
Assuming birth year is a string:
SELECT COUNT(*)
FROM MyClients
WHERE birth_year = '1972'
And if birth year is being used as an input control:
SELECT COUNT(*)
FROM MyClients
WHERE birth_year = $P{birth_year}
To count non-zero records in jasper use the expression below -
( $F{test} == 0.0 ? null : $F{test} )

How do I add an additional row to the result set to display total?

Here is my query:
SELECT p.Company
, p.Project_ID
, p.Name as 'Project_Name'
, p.Company
, t.Name as 'Task_Name'
, r.Owner
, t.Status
, r.Work_Date
, r.Minutes_Spent
, r.Type
, r.Description
FROM TK_Project p
INNER JOIN TK_Task t
ON p.Project_ID = t.Project_ID
JOIN TK_Time_Record r
ON t.ID = r.Task_ID
WHERE p.Company = 248
AND p.Name = 'Technical Support'
AND r.Work_Date BETWEEN '01/01/2012' AND '05/02/2012'
AND r.Type NOT LIKE '%non%'
--AND (
-- r.Type = 'Programming-Billable'
-- OR r.Type = 'Consulting-Billable'
-- )
AND (
r.Type = 'Data Maintenance'
OR r.Type = 'Tech Support-Billable'
OR r.Type = 'Training'
)
ORDER BY r.Work_Date DESC
Here is the data it returns:
Company Project_ID Project_Name Company Task_Name Owner Status Work_Date Minutes_Spent Type Description
------- ---------- ----------------- ------- ----------------- ------- ------- ----------------------- ------------- --------------------- ------------
248 512 Technical Support 248 Technical Support Tim Started 2012-03-06 00:00:00.000 15 Tech Support-Billable Notes.
248 512 Technical Support 248 Technical Support Patrick Started 2012-02-24 00:00:00.000 15 Data Maintenance Notes.
248 512 Technical Support 248 Technical Support Tim Started 2012-02-24 00:00:00.000 15 Tech Support-Billable Notes.
248 512 Technical Support 248 Technical Support Tim Started 2012-02-14 00:00:00.000 15 Tech Support-Billable Notes.
248 512 Technical Support 248 Technical Support Tim Started 2012-01-05 00:00:00.000 15 Tech Support-Billable Notes.
248 512 Technical Support 248 Technical Support Tim Started 2012-01-04 00:00:00.000 15 Tech Support-Billable Notes.
What is the best way for asp.net or in sql to grab a total of the Minutes_Spent column? I have tried to get WITH ROLLUP to work but could not get it to work correctly. I have tried COMPUTE but cannot have multiple result sets returned (maybe I could but not sure how to access it in asp.net)
Well given your question I guess a side request isn't what you look for.
As for asp, I found this post that might interest you, although you've tried it already :
How to calculate the sum of the datatable column in asp.net?
If filters are a problem, take a look at this post as well :
SUM datatable column with compute but NO filter
I hope it'll help you!

Resources