DS4PS / cpp-526-fall-2019

Course material for CPP 526 Foundations of Data Science I
http://ds4ps.org/cpp-526-fall-2019
4 stars 4 forks source link

Overview One #12

Open Taesian33 opened 5 years ago

Taesian33 commented 5 years ago

I'm reviewing the Overview again.

Would it be possible to have the correct answer somewhere?

I'm not sure if I'm doing things correctly, obviously, when I get ERROR I'm not, but for example, the Temperature questions, I think it would be really helpful to see an example.

castower commented 5 years ago

Hello Taesian33, For the temperature question, I used the following code and it returned the appropriate value:


ConvertToCelsius <- function( fahrenheit )

{
celsius <- ( fahrenheit - 32 ) * 5/9
temp.in.fahrenheit <- round( celsius )
return( temp.in.fahrenheit)
}

temp.in.fahrenheit <- 212
ConvertToCelsius( temp.in.fahrenheit )
lecy commented 5 years ago

That works!

I think you mixed up your naming conventions though:

ConvertToCelsius <- function( fahrenheit )
{
    celsius <- ( fahrenheit - 32 ) * 5/9
    temp.in.celsius <- round( celsius )
    return( temp.in.celsius )  # you should be returning in celsius
}

temp.in.fahrenheit <- 212
ConvertToCelsius( temp.in.fahrenheit )
lecy commented 5 years ago

@Taesian33 I will try to include solutions where I can. Feel free to post a question here if you are stuck or something doesn't make sense. Others probably have similar questions!

Taesian33 commented 5 years ago

I was lost, then I thought I was found, but now I'm beyond lost. I feel like now I'm lost AND blind.

Taesian33 commented 5 years ago
head( dat, 10 ) 
head( dat$owner, 10 )  # preview a vector 

What does that mean?

lecy commented 5 years ago

This is Courtney's code:

ConvertToCelsius <- function( fahrenheit )
{
   celsius <- ( fahrenheit - 32 ) * 5/9
   temp.in.fahrenheit <- round( celsius )
   return( temp.in.fahrenheit)
}

temp.in.fahrenheit <- 212
ConvertToCelsius( temp.in.fahrenheit )

If we think about it as a recipe instead of a function:

temp.in.fahrenheit <- 212
temp.in.celsius <- ( temp.in.fahrenheit - 32 ) * 5/9
temp.in.celsius <- round( temp.in.celsius )
temp.in.celsius

I just pointed out that in the middle of the function she had converted the temperature to Celsius, but then renamed it Fahrenheit.

ConvertToCelsius <- function( fahrenheit )
{
   celsius <- ( fahrenheit - 32 ) * 5/9
   temp.in.FAHRENHEIT <- round( celsius )   # should be CELSIUS
   return( temp.in.FAHRENHEIT )              # should be CELSIUS
}

temp.in.fahrenheit <- 212
ConvertToCelsius( temp.in.fahrenheit )

The code still works, it's just confusing to someone trying to understand what it is actually doing. Why would rounding the celsius temperature change the value to fahrenheit? It doesn't actually, we are just labeling it incorrectly.

lecy commented 5 years ago

head() prints the first six lines of a dataset or the first six values from a vector. tail() does the same thing but for the last six lines or values. They are functions to let you peek at your dataset without printing the whole thing on your screen (like if you just type dat).

On the lab, head( dat, 10 ) is what produces this data preview after knitting:

image

Taesian33 commented 5 years ago

### I think I'm back in the game

castower commented 5 years ago

This is Courtney's code:

ConvertToCelsius <- function( fahrenheit )
{
   celsius <- ( fahrenheit - 32 ) * 5/9
   temp.in.fahrenheit <- round( celsius )
   return( temp.in.fahrenheit)
}

temp.in.fahrenheit <- 212
ConvertToCelsius( temp.in.fahrenheit )

If we think about it as a recipe instead of a function:

temp.in.fahrenheit <- 212
temp.in.celsius <- ( temp.in.fahrenheit - 32 ) * 5/9
temp.in.celsius <- round( temp.in.celsius )
temp.in.celsius

I just pointed out that in the middle of the function she had converted the temperature to Celsius, but then renamed it Fahrenheit.

ConvertToCelsius <- function( fahrenheit )
{
   celsius <- ( fahrenheit - 32 ) * 5/9
   temp.in.FAHRENHEIT <- round( celsius )   # should be CELSIUS
   return( temp.in.FAHRENHEIT )              # should be CELSIUS
}

temp.in.fahrenheit <- 212
ConvertToCelsius( temp.in.fahrenheit )

The code still works, it's just confusing to someone trying to understand what it is actually doing. Why would rounding the celsius temperature change the value to fahrenheit? It doesn't actually, we are just labeling it incorrectly.

Ah, thank you! I missed that detail.

Taesian33 commented 5 years ago

@castower CAN you please explain what was the difference between yours and his? I'm going over it with a fine comb and failing to realize what was wrong or different btw the 2?

Taesian33 commented 5 years ago

@lecy Regarding LAB 1, I am having problems in regards to I'm not sure what to type in, I'm not even sure where to look up the information.

castower commented 5 years ago

@castower CAN you please explain what was the difference between yours and his? I'm going over it with a fine comb and failing to realize what was wrong or different btw the 2?

It's simply that I named the function temp.in.fahrenheit when it should have been named temp.in.celsius because the units had already been converted.

Taesian33 commented 5 years ago

@castower right.

How are you doing on Lab 1?

castower commented 5 years ago

@castower right.

How are you doing on Lab 1?

I was able to complete it, but I can't get it to knit for submission.

Taesian33 commented 5 years ago

@castower right. How are you doing on Lab 1?

I was able to complete it, but I can't get it to knit for submission.

Knit?

lecy commented 5 years ago

This might help with knit:

screencast gif

lecy commented 5 years ago

image