Closed LeeDelaino closed 4 years ago
I "assigned" to Ben but am happy to hear from anyone!!
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.
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?
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.
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.
@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:
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:
$
notation as we did in the first R lesson:
df$hsls_small_percent <- df$x4hs2psmos / rowSums(df$x4hs2psmos) * 100
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.
I don't think x4hs2psmos
is the variable you want to answer question 6. Also, don't forget to attend to missing values.
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. :)
Reopening since it's an all purpose thread. Thanks for the example code @brightstone1 (I've edited to add code blocks for clarity).
Closing since we've moved forward. Please open a new issue for the repeat of this assignment with pipes.
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?