Notes

How to sum columns row-wise in R quickly

Imagine I want to calculate the percentage of the vote that Kamela Harris got in Albany County using this data frame. I want to add up all the Kamela Harris columns and divide by the total votes in the Presidential race. There is a quick trick to do this with R using the tidyverse and purr library.

  mutate(
    harris_percent =
      reduce(select(., contains('kamala_d_harris')), `+`)/
      reduce(select(., contains('electors_for_president_and_vice_president')), `+`)
    )

The above code uses the reduce command against a subset of the dataframe containing the Kamala Harris columns which reduces them to one column in a vectorized format using the addition operator. You can use any vectorized operation or function rather then `+` there.

Here are column names for reference:

[1] "town"                                                             "ward"                                                            
[3] "ed" "ballots_cast_total_ballots_cast"
[5] "ballots_cast_blank_ballots_cast2" "electors_for_president_and_vice_president_dem_kamala_d_harris"
[7] "electors_for_president_and_vice_president_rep_donald_j_trump" "electors_for_president_and_vice_president_con_donald_j_trump"
[9] "electors_for_president_and_vice_president_wfp_kamala_d_harris" "electors_for_president_and_vice_president_write_in"
[11] "electors_for_president_and_vice_president_over_votes" "electors_for_president_and_vice_president_under_votes"
[13] "united_states_senator_dem_kirsten_e_gillibrand" "united_states_senator_rep_michael_d_sapraicone"
[15] "united_states_senator_con_michael_d_sapraicone" "united_states_senator_wfp_kirsten_e_gillibrand"
[17] "united_states_senator_lar_diane_sare" "united_states_senator_write_in3"
[19] "united_states_senator_over_votes4" "united_states_senator_under_votes5"
[21] "representative_in_congress_20th_district_dem_paul_d_tonko" "representative_in_congress_20th_district_rep_kevin_m_waltz"
[23] "representative_in_congress_20th_district_con_kevin_m_waltz" "representative_in_congress_20th_district_wfp_paul_d_tonko"
[25] "representative_in_congress_20th_district_write_in6" "representative_in_congress_20th_district_over_votes7"
[27] "representative_in_congress_20th_district_under_votes8" "state_senator_43rd_district_dem_alvin_gamble"
[29] "state_senator_43rd_district_rep_jake_ashby" "state_senator_43rd_district_con_jake_ashby"
[31] "state_senator_43rd_district_write_in9" "state_senator_43rd_district_over_votes10"
[33] "state_senator_43rd_district_under_votes11" "state_senator_46th_district_dem_patricia_a_fahy"
[35] "state_senator_46th_district_rep_ted_danz_jr" "state_senator_46th_district_con_ted_danz_jr"
[37] "state_senator_46th_district_wfp_patricia_a_fahy" "state_senator_46th_district_write_in12"
[39] "state_senator_46th_district_over_votes13" "state_senator_46th_district_under_votes14"
[41] "member_of_assembly_102nd_district_dem_janet_s_tweed" "member_of_assembly_102nd_district_rep_christopher_tague"
[43] "member_of_assembly_102nd_district_con_christopher_tague" "member_of_assembly_102nd_district_wfp_janet_s_tweed"
[45] "member_of_assembly_102nd_district_write_in15" "member_of_assembly_102nd_district_over_votes16"
[47] "member_of_assembly_102nd_district_under_votes17" "member_of_assembly_107th_district_dem_chloe_e_pierce"
[49] "member_of_assembly_107th_district_rep_scott_h_bendett" "member_of_assembly_107th_district_con_scott_h_bendett"
[51] "member_of_assembly_107th_district_write_in18" "member_of_assembly_107th_district_over_votes19"
[53] "member_of_assembly_107th_district_under_votes20" "member_of_assembly_108th_district_john_t_mc_donald_iii"
[55] "member_of_assembly_108th_district_write_in21" "member_of_assembly_108th_district_over_votes22"
[57] "member_of_assembly_108th_district_under_votes23" "member_of_assembly_109th_district_dem_gabriella_a_romero"
[59] "member_of_assembly_109th_district_rep_alicia_m_purdy" "member_of_assembly_109th_district_con_alicia_m_purdy"
[61] "member_of_assembly_109th_district_wfp_gabriella_a_romero" "member_of_assembly_109th_district_write_in24"
[63] "member_of_assembly_109th_district_over_votes25" "member_of_assembly_109th_district_under_votes26"
[65] "member_of_assembly_110th_district_dem_phillip_g_steck" "member_of_assembly_110th_district_rep_jeff_madden"
[67] "member_of_assembly_110th_district_con_jeff_madden" "member_of_assembly_110th_district_wfp_phillip_g_steck"
[69] "member_of_assembly_110th_district_write_in27" "member_of_assembly_110th_district_over_votes28"
[71] "member_of_assembly_110th_district_under_votes29" "district_attorney_dem_lee_c_kindlon"
[73] "district_attorney_rep_ralph_f_ambrosio" "district_attorney_wfp_lee_c_kindlon"
[75] "district_attorney_write_in30" "district_attorney_over_votes31"
[77] "district_attorney_under_votes32" "surrogate_court_judge_dem_deborah_s_kearns"
[79] "surrogate_court_judge_wfp_deborah_s_kearns" "surrogate_court_judge_write_in33"
[81] "surrogate_court_judge_over_votes34" "surrogate_court_judge_under_votes35"
[83] "family_court_judge_dem_jaime_lynn_czajka" "family_court_judge_dem_jillian_e_faison"
[85] "family_court_judge_dem_ricja_d_rice_ghyll" "family_court_judge_wfp_jasper_mills_iii"
[87] "family_court_judge_wfp_jillian_e_faison" "family_court_judge_wfp_ricja_d_rice_ghyll"
[89] "family_court_judge_write_in36" "family_court_judge_over_votes37"
[91] "family_court_judge_under_votes38" "county_legislator_county_legislative_district_5_dem_susan_m_pedo"
[93] "county_legislator_county_legislative_district_5_write_in39" "county_legislator_county_legislative_district_5_over_votes40"
[95] "county_legislator_county_legislative_district_5_under_votes41" "cohoes_city_council_member_ward_6_dem_april_m_trudeau"
[97] "cohoes_city_council_member_ward_6_con_justin_m_alesio" "cohoes_city_council_member_ward_6_vfa_april_m_trudeau"
[99] "cohoes_city_council_member_ward_6_write_in42" "cohoes_city_council_member_ward_6_over_votes43"
[101] "cohoes_city_council_member_ward_6_under_votes44" "town_justice_town_of_bethlehem_dem_erin_r_lynch"
[103] "town_justice_town_of_bethlehem_write_in45" "town_justice_town_of_bethlehem_over_votes46"
[105] "town_justice_town_of_bethlehem_under_votes47" "village_trustee_village_of_green_island_dem_michele_a_heffern"
[107] "village_trustee_village_of_green_island_dem_richard_r_jones_jr" "village_trustee_village_of_green_island_dem_joseph_a_liotta_sr"
[109] "village_trustee_village_of_green_island_write_in48" "village_trustee_village_of_green_island_over_votes49"
[111] "village_trustee_village_of_green_island_under_votes50" "village_trustee_village_of_green_island_dem_barbara_belokopitsky"
[113] "village_trustee_village_of_green_island_write_in51" "village_trustee_village_of_green_island_over_votes52"
[115] "village_trustee_village_of_green_island_under_votes53" "highway_superintendent_town_of_westerlo_dem_james_e_brush"
[117] "highway_superintendent_town_of_westerlo_rep_david_pecylak" "highway_superintendent_town_of_westerlo_con_david_pecylak"
[119] "highway_superintendent_town_of_westerlo_write_in54" "highway_superintendent_town_of_westerlo_over_votes55"
[121] "highway_superintendent_town_of_westerlo_under_votes56" "proposal_one_an_amendment_yes"
[123] "proposal_one_an_amendment_no" "proposal_one_an_amendment_over_votes57"
[125] "proposal_one_an_amendment_under_votes58" "proposal_two_town_of_bethlehem_yes59"
[127] "proposal_two_town_of_bethlehem_no60" "proposal_two_town_of_bethlehem_over_votes61"
[129] "proposal_two_town_of_bethlehem_under_votes62"

Family Day at the Nutcracker πŸŽ„

Today it’s off to see the Nutcracker that my niece is preforming at down at SUNY then having a dinner with my parents at a local Mexican restaurant. It’s nice to spend family time together, as you never know how much longer this going to last.

In some ways, it’s nice to dream that these days will last forever, πŸ‘ͺ that your parents aren’t getting older and gray even faster then you are yourself. I do spend a fair amount of time with the parents, and while we all agree there will be a next time, you never really know if that will be the case. That’s why I am also planning to visit with them on Christmas Eve or Christmas Day — still deciding when I want to leave for my adventure for the week off.

I am considering going out to the Finger Lakes on Christmas Day through New Years Day 🎊 but I worry about the weather, and its a long trip out there. I also am thinking about a Central NY trip, but if it’s seven days and I can only camp in one location β›Ί for three so I’d be looking at different locations every few nights. I thought about doing Long Pond and then heading up to the Horse Camp for New Years Eve, 🐴 but that’s only six nights unless maybe I camp at Beaver Creek. Also, have to consider snow depth, and the issue of staying parked too long in one location and not being able to keep the battery charge up. πŸ”‹ And just that winter nights are often cold and long — do I want to spend 6 or 7 nights alone in wilderness? 🐺 And the whole issue that next weekend might rain. 🌧 I need to decide by Monday so I can get propane and supplies as grocery stores are closed on Christmas, and to tell my folks when I plan to visit for Christmas. πŸŽ…

It’s good to be back home,  πŸ₯Ά it was so cold on Saturday morning at Rensselaerville State Forest. It’s was a beautiful night with the snow Friday night ❄️ but it was so frigid with the wind come the morning. That’s one of things that has me reconsidering camping on for a full seven days starting Christmas Day. πŸŽ… I am not saying I won’t go down to Long Pond and maybe the horse camp for a few days, but a full trip out to the Finger Lakes seems a bit much for this time of year, especially if we get that heavy rain next week.

Tomorrow I’d like to ride my bike to work, 🚲 but I haven’t had a chance to service the brakes, it’s going to be quite cold, and I’m concerned there will be a lot of ice on the bike trail. I might instead bus it to work. I have black beans soaking to cook up in the morning, and I’m thinking of baking bread. 🍞 We will see, it’s a cold night. Plus I should thinking about doing my wash.

11 degrees in the morning. πŸ₯Ά

The temperature wasn’t bad but the wind and blowing snow was cold when I finally got out around 9 am. My skin got so dried out cooking breakfast and taking down camp, it feels like a sun burn from the wind. With so much wind even the propane heater didn’t seem super warm.

I don’t heat my truck cap but I’m plenty warm under the stack of old sleeping bags I use. People think you need speciality gear for winter camping but that’s not true. What you need is to be dry, out of the wind and with a decent layer of insulation to keep your body heat in. As I’ve gotten older I find the circulation in my feet and toes isn’t quite as good so I do wear dry fresh cotten socks overlaid by wool socks to ensure that I don’t have cold feet. And always gloves when I’m not under the covers.

Last evening was beautiful with the snow and not cold due to the lack of wind. I will take a 10 degree evening over a 40 degree windy evening any day. Wind matters far more than temperatures. That said, when it’s very cold I do watch the starting battery on my truck like a hawk as the voltage sags with the cold and oil thickens and I don’t want a weak start when it’s time to go home. I will in the winter idle the truck every other day to bring the engine to 210 degrees to top off the battery and make sure oil gets pumped through the engine at temperature to reduce the risks of weak starts.

Not camping tonight mostly due to the wind and I’m doing a family event tomorrow.

15 degrees and the wind is roaring πŸ₯Ά

I’m good starting out my winter hiding under the covers. At some point I’ll face the morning, make some coffee and sit by the heater but I’m not rushing.

It’s cold outside. 🌬️ But it’s winter and that’s to be expected. I’m in no rush to get outside as with the wind it will be only colder and it’s comfortable under the covers. The heater and hot coffee β˜• will be nice but I also want to delay taking down camp πŸ•οΈ and not leave until midday πŸ•› when the roads are better.

With the snow β˜ƒοΈ and no wind yesterday it was pretty camping and not super cold ❄️ by the standards leading up to Christmas πŸŽ„. It was fun listening to podcasts and enjoying the fire πŸ”₯ which I kept fairly small – warm enough but not burning through too much wood. πŸͺ΅Pretty too with the snow coming down.

I’m thinking about getting up around nine, 9️⃣ making a nice breakfast 🍳 and sitting by the heater, and then take camp down around ten into eleven and maybe doing a hike to enjoy the woods covered in snow. Head home around noontime, carefully driving in the snow 🚘 and getting home and things put away in the afternoon and maybe grocery shopping πŸ›’ in the evening or I could wait until morning. Tomorrow is my family πŸ‘ͺ event, going to see my niece at the Nutcracker ballet. πŸ₯œ