R has several basic data types that you should be aware of:
1. Numeric:
This data type represents numbers and can be either integer or floating point. You can create a numeric variable in R as follows:
x <- 5 # integer y <- 3.14 # floating point
2. Character:
This data type represents text and is enclosed in quotes. You can create a character variable in R as follows:
x <- "hello" y <- 'world'
3. Logical:
This data type represents boolean values, which are either TRUE or FALSE. You can create a logical variable in R as follows:
x <- TRUE y <- FALSE
4. Integer:
This data type represents integers and is a subtype of numeric. You can create an integer variable in R using the L suffix:
x <- 5L
5. Complex:
This data type represents complex numbers, which are a combination of real and imaginary numbers. You can create a complex variable in R as follows:
x <- 3 + 4i
6. Raw:
This data type represents raw bytes and is used for low-level manipulation of binary data. You can create a raw variable in R as follows:
x <- charToRaw("hello")
In addition to these basic data types, R also has more advanced data structures, such as vectors, matrices, arrays, data frames, and lists, which can hold multiple values of the basic data types. Vectors can hold values of the same type, while matrices and arrays can hold values of the same type in a two-dimensional or multi-dimensional format. Data frames can hold values of different data types in a tabular format, like a spreadsheet. Lists can hold values of different data types in a structured format, like a dictionary.
It's worth noting that R is a dynamically-typed language, which means that you don't need to declare the data type of a variable before using it. R will automatically assign a data type based on the value of the variable.