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"

How to Manually Enter Raw Data in R?

In this article, we will discuss how to manually enter raw data in the R Programming Language.

In the R Language, we work with loads of different datasets by importing them through a variety of file formats. But Sometimes we need to enter our own raw data in the form of a character vector, a data frame, or a matrix. There are multiple methods to enter the raw data manually in the R Language.

Similar Reads

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....

Enter data as a data frame

...

Enter data as a matrix

To enter data as a data frame in the R Language, we use the data.frame() function. The data.frame() function creates data frames that are tightly coupled collections of variables. These data frames are widely used as the fundamental data structure in the R Language. A single data frame can contain different vectors of different classes together thus it becomes one data structure for all the needs....

Contact Us