edquant / edh7916

Course materials and website for EDH7916: Contemporary Research in Higher Education
https://edquant.github.io/edh7916/
3 stars 1 forks source link

Homework (assignment 3) --- am stuck. #9

Closed LeeDelaino closed 4 years ago

LeeDelaino commented 4 years ago

We have made it to question 6 but have come to a screeching halt. Any hints or suggestions to point us in the right direction?

LeeDelaino commented 4 years ago

I "assigned" to Ben but am happy to hear from anyone!!

btskinner commented 4 years ago

Adding @edquant/team_class to make sure people see this (remember, if you "reply" to the email, you are also posting to the public course issues page). You can respond to the thread here.

@LeeDelaino, thanks for making this a public request. It might help others to share code that has gotten you part of the way there. Or share code that hasn't worked at all. If you don't have any code yet, just saying a little more about your thought process would be useful.

klvogelanderson commented 4 years ago

I am stuck because the NCES website has been down all morning. I have no access to the codebook. Is there any other way to get access?

LeeDelaino commented 4 years ago

Yes--i just learned of this too! But in terms of Ben's prior question--I haven't really tried any code because I actually don't know where to start.

btskinner commented 4 years ago

I see that the NCES website is intermittently down. I've added the HSLS codebook PDF to our site materials. You can get it either by:

  1. Visiting here and clicking the download button
  2. Downloading directly via this link

Hopefully the site is up soon, but this PDF should have the information you need.

LeeDelaino commented 4 years ago

Per Niki's suggestion tried running:

hsls_small_percent <- x4hs2psmos / rowSums(x4hs2psmos) * 100

got an error:

Error: object 'x4hs2psmos' not found

Not sure why because I read the hsls_small file, and did the select command as had been doing in all previous problems.

btskinner commented 4 years ago

@LeeDelaino, I added some formatting to your comment above to make the code clearer (click the ... and then Edit to see).

A couple of points:

Error not finding the object

I don't see the full script, but R can't find x4hs2psmos b/c it doesn't exist as its own object in your environment. Most likely, you are referencing the x4hs2psmos column in the data frame object (remember, box inside a box). I don't know what you've called that, but assuming it is df, then R can only see the x4hs2psmos column if you tell it to look inside df first.

One of two ways:

  1. Use the $ notation as we did in the first R lesson:
    df$hsls_small_percent <- df$x4hs2psmos / rowSums(df$x4hs2psmos) * 100
  2. Use a tidyverse function and put the data frame first:
    df <- mutate(df, hsls_small_percent = x4hs2psmos / sum(x4hs2psmos) * 100)

I would prefer that you use the tidyverse way throughout, but if you get an answer the other way, that's fine.

Check your variable

I don't think x4hs2psmos is the variable you want to answer question 6. Also, don't forget to attend to missing values.

brightstone1 commented 4 years ago

Hi, everyone:

## to calculate percentage of column x4hs2psmos, first calculate total and create new column
df_tmp$total <- sum(df_tmp$x4hs2psmos)
## then using new column, we can divide x4hs2psmos over Total column, * 100
df_tmp$percenttotal <- df_tmp$x4hs2psmos / df_tmp$total * 100
## to view results
df_tmp​

Now that we have 10 columns (2 new + original 8) we can view the new spreadsheet/database via this command: View(df_tmp) or by double-clicking the last df in your Environment. Hope that helps. Niki P.S. It turns out you may not want to calculate percentages of x4hs2psmos after all. But, at least we know how to calculate percentages, even if we apply it to another column/field. :)

btskinner commented 4 years ago

Reopening since it's an all purpose thread. Thanks for the example code @brightstone1 (I've edited to add code blocks for clarity).

btskinner commented 4 years ago

Closing since we've moved forward. Please open a new issue for the repeat of this assignment with pipes.