bigdatahci2015 / forum

0 stars 4 forks source link

Extracting Instructor Name when using _.mapValues #18

Closed KevinKGifford closed 9 years ago

KevinKGifford commented 9 years ago

I have been struggling with extracting the name of the course instructors 'Instructors', which is an array, when using the .mapValues() function following the typical .groupBy(data, ....) object generation. Non-array values extract easily/as expected. Can anyone point me to / hint at what I need to because I seem to be making this much more difficult than I'd expect it to be?

karisantos commented 9 years ago

Hi Kevin - I use _.map() when I have an array. In the last problem of the warm up I ended up using filter/where Hope that is enough of a hint. Kari

KevinKGifford commented 9 years ago

Hi Kari - thanks for the reply. I can extract the 'Instructor" name properly when using .map (via .pluck) ala the final warm-up exercise. When I attempt to do the same operation inside of _.mapValues it fails and I'm trying to understand why. In my case, I want to return a key-value pair of 'AvgInstructor' (key) and "Instructors' (value which is a string) so I can output in a table (to show which Instructors have low Instructor ratings).

So thanks - you do what I tried as well, I just need to be able to perform the same "logical" operation when using _.mapValues and I just haven't figured out how to make it work. Thanks again for the kind reply - much appreciated.

Kevin

On Thu, Sep 17, 2015 at 7:44 PM, karisantos notifications@github.com wrote:

Hi Kevin - I use _.map() when I have an array. In the last problem of the warm up I ended up using filter/where Hope that is enough of a hint. Kari

— Reply to this email directly or view it on GitHub https://github.com/bigdatahci2015/forum/issues/18#issuecomment-141303823 .

KevinKGifford commented 9 years ago

I figured out how to do this with assistance from Karen Blakemore (thanks Karen!!). I personally found this to be sticky so I'll post to the group in the case that it may help somebody. For the data set given I wanted to extract the names of the Instructors which was a key-value array (see the data slice in fcq/index.md. To pull out names of the course instructors the solution (Karen/I) utilized was:

return .mapValues(groups, function(d) { return .pluck(.flatten(.pluck(d, 'Instructors')), 'name') })

Hope this helps somebody.

Kevin