Expressions and Variables

More Variables


Calculate a total weight in pounds of 20 bushels of soybeans and then convert it to kilograms. The total weight is simply the sum of the weight of all 20 bushels, but in this case we know that the weight of one bushel of soybeans is 60 pounds.

  1. Add a new section to your R script starting with a comment.
  2. Create a variable bushel and assign it the mass of a single bushel.
  3. Create a variable bushels and assign it the number of bushels.
  4. Create a variable bushel_tot and assign it a value by multiplying the two variables together.
  5. Convert the value of bushel_tot into kilograms and assign this value to a new variable.
  6. Print the final answer to the screen.

Think about the choice of variable names. If we came back to the code for this assignment in two weeks (without the assignment itself in hand) would we be able to remember what these variables were referring to and therefore what was going on in the code? The variable name bushel is also kind of long. If we had to type it many times it would be faster just to type b. We could also use really descriptive alternatives like bushel_weight_in_pounds. Or we would compromise and abbreviate this or leave out some of the words to make it shorter (e.g., bshl_lbs).

Think about appropriate variable names and then rename the variables in your program to what you find most useful.

[click here for output]