Keeping Specific Data

In this activity, you'll select only responses that meet specific criteria and count them.

Snap! has two built-in blocks that may be useful to your data analysis:

  1. Open your "Data Dos" project if it isn't open already.
  2. Test the length block by using it to count the number of responses to your survey.

You can use keep to select specific responses. For example, you could keep just the "soccer" responses to question 1:
'my survey' watcher: a table with three rows and two columns. Row 1 column 1 has the text: 'Favorite sport?' and row 1 column 2 has the text: 'Years played?' Row 2 has the values 'soccer' and '4'. Row 3 has the values 'basketball' and '3'. Row 4 has the values 'soccer' and '5'. keep items (( ) = ('soccer')) from (responses to question (1) from survey (my survey)) reporting the list {'soccer', 'soccer'}

Or as another example, you could keep just the responses to question 2 that were greater than 3:
keep items (( ) > (3)) from (responses to question (2) from survey (my survey)) reporting the list {4, 5}

As with map, the empty slot in the first input to the keep function (that is, in ( ) = (soccer) or ( ) > (3)) is where each item from the list (e.g., each response to a specific survey question) goes every time the input function (( ) = (soccer) or ( ) > (3)) is applied.

  1. Try using keep to filter your data at least two times. Filter the data for two different questions using two different criteria.

You can use length together with keep to learn specific things about your data. For example, if you wanted to know how many people that you surveyed named soccer as their favorite sport, you could do:
('length') of (keep items (( ) = ('soccer')) from (responses to question (1) from survey (my survey))) reporting '2'

And if you wanted to know how many people said that they've played their favorite sport for more than 3 years, you could do:
('length') of (keep items (( ) > (3)) from (responses to question (2) from survey (my survey))) reporting '2'

  1. Use length together with keep to discover one or more things about your data.
    There are additional functions hidden behind the <, =, and > functions. To access them, right click the block, select "relabel...", and choose the function you want. Click for a demonstration.
    animation showing the > block, its right-click menu open with 'relabel...' selected, then another menu open showing additional predicate blocks with ≥ selected, and finally just the ≥ block in place of the > block. The animation cycles through selecting a variety of different predicate blocks.
  2. Talk with Your Partner Describe what your code does.
    For example: This code tells us that 2 survey respondents said "soccer" was their favorite sport on question 1.
    ('length') of (keep items (( ) = ('soccer')) from (responses to question (1) from survey (my survey))) reporting '2'
  3. Now Is a Good Time to Save

In this activity, you used length together with keep to begin analyzing your data.