0% found this document useful (0 votes)
40 views1 page

Ex1-Basic Data Types

The document discusses understanding basic data types in R by walking through an example of a kid buying chocolates with money. It demonstrates integer, numeric, character, and complex data types and performing operations like extracting substrings and computing square roots.

Uploaded by

Bhuvana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views1 page

Ex1-Basic Data Types

The document discusses understanding basic data types in R by walking through an example of a kid buying chocolates with money. It demonstrates integer, numeric, character, and complex data types and performing operations like extracting substrings and computing square roots.

Uploaded by

Bhuvana
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Understanding Basic Data Types in R

Ram went to a shop to buy chocolates. He carried Rs. A in his pocket where ‘A’ is a real
number (For eg., 10.5 means 10 Rupees 50 paise). He bought ‘B’ chocolates for the Rupee
part of the money he had. where ‘B’ is an integer value (for eg., 5 means 5 chocolates).
Compute the cost of a chocolate.

1) Let the money be denoted as variable A. Assign a decimal value to it and display it.
2) Print the class name of the variable A.
3) Check whether the variable A is of type ‘numeric’.
4) Let the number of chocolates be denoted as variable B. Assign an integer value to it
and display it.
5) Check whether the variable B is of type ‘integer’.
6) Create a variable C which stores the rupee part of the money he carried.
7) Compute the cost of a chocolate.
8) Represent the money as character string.
9) Store the first name and last name of the kid.
10) Display the message “<firstname lastname> bought <B> chocolates”

Consider the kids rhymes “Twinkle Twinkle Little Star”

11) Extract the substring “Little ” from the rhymes.


12) Replace “Little” as “Big”.

Babu wanted to know about complex number. Help him to understand the real and imaginary
part of the complex number. Show him that square root of a negative value can be computed
by converting it into a complex number.

13) Assign a complex number to a variable X.


14) Display the real part of X.
15) Display the imaginary part of X.
16) Compute square root of a negative number.
17) Check whether real part of X is greater than its imaginary part.

You might also like