moving data from Spreadsheet into 2Var based on a category

01212015, 06:19 AM
Post: #1




moving data from Spreadsheet into 2Var based on a category
I have data in the Spreadsheet app (circumference of wrist in inches, height in inches, gender) and I'd like to do 2Var stats using wrist and height values, but grouped by gender. I'd like to copy wrist values for males in C1, height values for males in C2, and wrist values for females in C3, and height values for females in C4. This way, I can do 2Var stats on males and females separately.
But I'm stuck on how to do this copy/filter operation. Conceptually, I want something like "insert wrist values into C1 if gender is male", and so on. I'd like to avoid sorting the spreadsheet by gender, then copying cell regions from the Spreadsheet into 2Var using the Home view. A program to do this would be cool (I'd learn a lot). The wrist/height/gender columns contain: Code:


01212015, 10:22 PM
(This post was last modified: 01212015 10:24 PM by Snorre.)
Post: #2




RE: moving data from Spreadsheet into 2Var based on a category
Hello mbeddo,
Here's a simple program that is not very efficient/elegant but more a concept. It allows arbitrary count of rows and is easy to extend for new types (e.g. "C" for cats). Code: get_x_where_y_equals_z(x,y,z) When running "DoStat", current app doesn't matter since it will always changed. Greetings 

01212015, 11:51 PM
Post: #3




RE: moving data from Spreadsheet into 2Var based on a category
Hello Snorre,
Thank you! It works just fine. I also have a TI nSpire, and the operation to filter a list based on a criteria is something that is lacking there as well, yet needing to filter lists comes up quite common in basic data analysis. Functional languages typically have a function that is prototyped something like "filter(fun, x)" where "x" is a list of "things" and "fun" is a Boolean function that is called as we iterate through "x". The output is a filtered list  those elements in "x" that satisfy your criteria. You kindly provided me with a "gem" (get_x_where_y_equals_z) which I will tuck away in a safe place. When I learn more about programming the HP Prime, maybe I'll end up with a more functional filter function. 

01222015, 09:44 AM
(This post was last modified: 01222015 11:10 AM by Snorre.)
Post: #4




RE: moving data from Spreadsheet into 2Var based on a category
Hello mbeddo,
the provided filter function was meant as a generic building block: easy to read, easy to understand, easy to customize. A more efficient solution would probably not iterate four times over the row set but only once and distribute the values directly to C1, ..., C4. (Well, the Prime is so blazingly fast, one may not even notice a speedup). If you're interested in the functional approach, take a closer look to the CAS function "select". (I think it doesn't improve speed or easytounderstand'ness but is quite more fun to puzzle out a single expression doing the filtertask.) Greetings 

« Next Oldest  Next Newest »

User(s) browsing this thread: 1 Guest(s)