Entering Data
How to Manually Enter Raw Data in R?
Enter data as a vector
To enter data as a vector in the R Language, we use the combine function i.e. c(). The c() function is a generic function that combines its arguments to form a vector. All arguments are coerced to a common type. To create a numeric vector we pass numbers as arguments to the c() function. To create a character vector we pass the strings or characters as arguments to the c() function.
Syntax: sample_vector <- c( data1, data2, ….. , datan )
where: data1, data2…: determines the numeric values that comprise the vector.
Example: Demonstrating basic character and numeric vectors.
R
# create numeric vector
numeric <- c(1,2,3,4,5)
# create character vector
character <- c("geeks", "for", "geeks")
# print vectors and their class
print("Character vector:")
character
print("Class:")
class(character)
print("Numeric vector:")
numeric
print("Class:")class(numeric)
Output:
Character vector: "geeks" "for" "geeks" Class: "character" Numeric vector: 1 2 3 4 5 Class: "numeric"