Practicing Data Types¶
Create a variable called
my_name
and assign your name to it.Check the class of
my_name
using theclass()
function.Now a weird one. Create a variable called
ten
and assign in the value"10"
in quotes. What’s the class often
? Why is it not numeric?What happens if you add
my_age
andten
?To convert
ten
to a numeric type, typeten = as.numeric(ten)
. Now check it’s class again.Now can you add
my_age
toten
?
Solutions¶
Here’s the deal with programming: the only way to learn to program is to wrestle with solving your own problems. The best way to learn is to do so actively – if you just look at answers as soon as you get stuck, your process is more passive. You may feel like you’re learning more, but research shows that that’s an illusion – students who learn passively think they’re learning more than they are (a summary of work in this area is here).
Moreover, in coding in particular, the process of debugging your code is a critical skill in and of itself, and the only way you will learn to do it is by literally spending hours working through your own problems. And once you’ve seen an answer, there’s no way to unsee it, so proceed only if you absolutely have to.
OK, if you still want to proceed, you can find solutions here.