Stuck with identifying variable data type

Hi Learning Folks,

I got stuck with identifying variable data types topic in R courses.

As it is explained that “class(variable_name)” and the result of it showed as it is a character data type but in previous exercises i learnt that character literal should always be wrapped in single or double quotation marks or apostrophes. However, here it is not enclosed it between quotes. so how come it can be declared as character data type???

course link is :

Also, when I ran the code it gave me an output with these numeric data type

q_1 <-total_purchase_cost
q_2 <-total_selling_cost
q_3 <-profit_1


[1] "numeric"
[1] "numeric"
[1] "numeric"

why is it so?? because the first two should be of character data type and the last one should be of numeric but it is showing all of them as numeric. why??

Can anybody help me with this topic.


On the previous screen, we have

total_purchase_cost <- 10.50 * 200L + 21.15 * 50L + 3.2 * 500L
total_selling_cost <- 12.10 * 200 + 24.90 * 50 + 4.99 * 500
profit_1 <- total_selling_cost - total_purchase_cost

The multiplication of the integer L and numeric (double) gives you a numeric. The total_purchase_cost, total_selling_cost, and profit_1 came from here.

When you check their data type below, they are all numeric. They have been assigned their respective values from the above.

q_1 <-class(total_purchase_cost)
q_2 <-class(total_selling_cost)
q_3 <-class(profit_1)

1 Like