In R, you can manually enter raw data in using c() function to create vectors.

The following methods shows how to do it with syntax.

Method 1: Enter Raw Data Using Vector

x <- c(value1,value2,...)


Method 2: Enter Raw Data to a Data Frame

data.frame(vector1, vector2, vector3)


Method 3 : Enter Raw Data in Matrix

cbind(vector1,vector2,...)


The following examples shows how to enter raw data in R.

## Create Vector to Enter Raw Data

Let’s see example to create vector:

# Create vector
vector_1 <- c(1,2,3,4,5,6,1.2,11.2,63.4)

# Print vector
print(vector_1)

# Check class of vector
class(vector_1)


Output:

 1.0  2.0  3.0  4.0  5.0  6.0  1.2 11.2 63.4

"numeric"


As we can see the output of above code it shows vector and using class() method we also check its class.

## Create Data Frame to Store Data

Once vector is created you can combine them to create data frame. We can use data.frame() function.The syntax for this is:

Let’s see code for this and also check class of this what it shows.

# Create data frame
df <- data.frame(Machine_name=c("Mach_1","Mach_2","Mach_3","Mach_4"),
Pressure=c(12.30,11.45,13.25,14.20),
Working=c(TRUE,FALSE,FALSE,TRUE))

# Print data frame
print(df)

# Display class
class(df)


Output:

Machine_name Pressure Working
1       Mach_1    12.30    TRUE
2       Mach_2    11.45   FALSE
3       Mach_3    13.25   FALSE
4       Mach_4    14.20    TRUE

"data.frame"


The output shows data frame which created using data.frame() function.

## Create Matrix to Store Data

Let see example for this:

# Declare vectors
Machine_name = c("Mach_1","Mach_2","Mach_3","Mach_4")
Pressure = c(12.30,11.45,13.25,14.20)
Working = c(TRUE,FALSE,FALSE,TRUE)

# Create matrix
matrix_1 = cbind(Machine_name,Pressure,Working)

# Display matrix
print(matrix_1)

# Display class of matrix
class(matrix_1)


Output:

Machine_name Pressure Working
[1,] "Mach_1"     "12.3"   "TRUE"
[2,] "Mach_2"     "11.45"  "FALSE"
[3,] "Mach_3"     "13.25"  "FALSE"
[4,] "Mach_4"     "14.2"   "TRUE"

"matrix" "array"


The output shows matrix which created using matrices also check its class.

Using all this method you can store raw data in vector, matrix and data frame.