how to count over everything in r studio - rstudio

I organizaed my data so that I get an output that gives me counts by modality. for example,
Resident Location Year Modality PGY ModalityCount
47 john smith SMH 2009-2010 CT PGY2 12
48 john smith SMH 2009-2010 MRI PGY2 4
However, I would like to make the counts overall counts of how many counts of scans they did overall.
How would i do this?
Thanks

Related

Generate a team from a list of unique players based on priority number. 3 Arrays of signups for different role

Im trying to create an application that would form a team of 4 people in a shooter game.
There are 3 roles for 4 players. We need 2x assault, 1x sniper and 1x medic in a team.
I would be choosing players from 3 arrays, each array contains signups for that role (playername and priority number). Players can signup for multiple roles.
Sniper[0] John 100
Sniper[1] Mort 91
Sniper[2] Stef 70
Medic[0] Jerry 92
Medic[1] Mort 91
Medic[2] Jambo 19
Assault[0] Jerry 92
Assault[1] Haler 91
Assault[2] Gowgow 79
Assault[3] Jambo 19
This is how the 3 arrays would look like.
Selection in this case should be:
Sniper - John 100
Medic - Mort 91
Assault1 - Jerry 92
Assault2 - Haler 91
Application should always try to select people with highest priority for available roles.
If anyone could at least point me in the right direction on how to solve this issue. Im really stuck here as I have no idea how to do it and I don't know what to search for online either, to learn.
I solved my selection problem with a "Hungarian algorithm or Munkres".

PowerQuery order of words in Text.Combine

Using PowerQuery in Excel 2016 to combine words in one column by the Category stored in another column. I use GroupBy with Text.Combine in it.
I am expecting the order of words to be sustained but it seems random.
There are 3 pictures below
first is my original table before SORT.
MAPPED WORDS is what i need combined, CATEGORY is the bucket of the combinations,
POSITION is the column which indicates the position of MAPPED WORD in SKU - i sort words in that order expecting that Text.Combine would retain that in the final strings. I am interested in red and blue-highlighted words for this example.
ORIGINAL TABLE
Market Tag SKU Position Category Mapped Word
ABG 130 HELLO DAY CRYSTAL MIDI GRANOLA CHOCOLATE 11 BRAND Crystal
ABG 130 HELLO DAY CRYSTAL MIDI GRANOLA CHOCOLATE 7 BRAND Day
AAI 30 FINAX HEALTHY GOOD MUESLI APPLE NUT RAISIN 1 BRAND Finax
AAI 30 FINAX HEALTHY GOOD MUESLI APPLE NUT RAISIN 7 OTHER Healthy
ABG 130 HELLO DAY CRYSTAL MIDI GRANOLA CHOCOLATE 1 BRAND Hello
ABG 130 HELLO DAY CRYSTAL MIDI GRANOLA CHOCOLATE 19 BRAND Midi
AAI 30 FINAX HEALTHY GOOD MUESLI APPLE NUT RAISIN 20 TYPE Muesli
AAI 30 FINAX HEALTHY GOOD MUESLI APPLE NUT RAISIN 33 FLAVOURS Nuts
AAI 30 FINAX HEALTHY GOOD MUESLI APPLE NUT RAISIN 37 FLAVOURS Raisins
ABG 130 HELLO DAY CRYSTAL MIDI GRANOLA CHOCOLATE 32 FLAVOURS Chocolate
AAI 30 FINAX HEALTHY GOOD MUESLI APPLE NUT RAISIN 27 FLAVOURS Apple
ABG 130 HELLO DAY CRYSTAL MIDI GRANOLA CHOCOLATE 24 TYPE Granola
AAI 30 FINAX HEALTHY GOOD MUESLI APPLE NUT RAISIN 15 BRAND Good
AFTER SORT
AFTER GROUPBY-COMBINE.
The problem is that the result does not look like any logic - the order is ignored. Red words are appended in alphabetical order, whilst blue with no specific order.
I need the words combined in the order as per POSITION column.
It's the same answer I gave to a different question around operations after sorting, but I tested it and if you put your sorting step inside Table.Buffer() it seems like that works here as well.
Table.Buffer(Table.Sort(PROPERCASE_WORDS,{{"TAG",Order.Ascending},{"CATEGORY",Order.Ascending}, {"POSITION",Order.Ascending}}))
AFAIK Table.Buffer loads the table into memory and in doing so resets an internal index used by various PQ operations to match the current sorting of the table. I don't know if there are any downsides to doing this, but it seems to work in a number of cases where you want an operation to proceed in a "top to bottom" manner.

Why doesn't Javers report the correct row(s) that was added when comparing two objects?

When comparing two objects of the same size, Javers compares 1-to-1. However, if a new change is added such as new row to one of the objects, the comparison reports changes that are NOT changes. Is it possible to have Javers ignore the addition/deletion for the sake of just comparing like objects?
Basically the indices get out of sync.
Row Name Age Phone(Cell/Work)
1 Jo 20 123
2 Sam 25 133
3 Rick 30 152
4 Rick 30 145
New List
Row Name Age Phone(Cell/Work)
1 Jo 20 123
2 Sam 25 133
3 Bill 30 170
4 Rick 30 152
5 Rick 30 145
Because Bill is added the new comparison result will say that Rows 4,5 have changed when they actually didn't.
Thanks.
I'm guessing that your 'rows' are objects representing rows in an excel table and that you have mapped them as ValueObjects and put them into some list.
Since ValueObjects don't have its own identity, it's unclear, even for a human, what was the actual change. Take a look at your row 4:
Row Name Age Phone(Cell/Work)
before:
4 Rick 30 145
after:
4 Rick 30 152
Did you changed Phone at row 4 from 145 to 152? Or maybe you inserted a new data to row 4? How can we know?
We can't. By default, JaVers chooses the simplest answer, so reports value change at index 4.
If you don't care aboute the indices, you can change the list comparision algorithm from Simple to Levenshtein distance. See https://javers.org/documentation/diff-configuration/#list-algorithms
SIMPLE algorithm generates changes for shifted elements (in case when elements are inserted or removed in the middle of a list). On the contrary, Levenshtein algorithm calculates short and clear change list even in case when elements are shifted. It doesn’t care about index changes for shifted elements.
But, I'm not sure if Levenshtein is implemented for ValueObjects, if it is not implemented yet, it's a feature request to javers-core.

Region (not country) codes for table rates shipping in Magento 1.9

I'm adding table rates shipping method to a Magento install.
My rates are divided per weight in 6 different ranges 0-3 | 3-6 | 7-10 | 11-25 | 26-50 | 50-100 always the same in the whole Italy except for 3 regions.
In these regions prices for same weight ranges are slightly different. So It would be super good being able to add region codes into the right field, but where I can find those codes?
Headers into CSV are:
Country,Region/State,"Zip code","Weight (and Above)","Shipping Price"
I need to undrstand what I must add to the "Region/State" filed.
Adding different prices using Zip Codes would mean adding 7056 lines to my CV manually!
TNKS.
Go and look at this table in your magento database;
select * from directory_country_region
This reveal all the regions currently in your store;
1 US AL Alabama
2 US AK Alaska
3 US AS American Samoa
4 US AZ Arizona
5 US AR Arkansas
6 US AE Armed Forces Africa
7 US AA Armed Forces Americas
8 US AE Armed Forces Canada
9 US AE Armed Forces Europe
10 US AE Armed Forces Middle East
etc. Column C is the region code. You can add to this if required.

Sorting multiple NSMutableArrays

I have high scores (name, score, time) stored in a single file and I divide them into separate arrays once it reads them, only problem is I can't figure out a way to sort all three by score and time from least to greatest and still keep the correct order of values.
For example:
Name score time
---------------
nathan 123 01:12
bob 321 55:32
frank 222 44:44
turns to:
bob 123 01:12
frank 222 44:44
nathan 321 55:32
Encapsulate the data into a single object (HighScore) that has three properties: name, time, and score. Then store them in a single array and sort the single array.
Welcome to object-oriented programming.

Resources