Here we are explaining how to write an R program to convert a data frame column to a vector. For that we are using a built-in function data.frame(). This function helps to create data frames, tightly coupled collections of variables that share many of the properties of matrices and of lists. The syntax of this function is
– Where dots(…) indicates the arguments are of either the form value or tag = value and row. name is a NULL or a single integer or character string.
Below are the steps used in the R program to convert a data frame column to a vector. In this R program, we directly give the data frame to a built-in function. Here we are using the variables Df1, Df2, Df3, Df4 for holding data frames. Consider the variable A for holding the converted vector. The data frame is converted by using the function data.frame(). The function is done as like data.frame(Df1=5:9, Df2=1:5, Df3=10:14, Df4=15:19). Finally, print the result vector.
Df1 = c(5, 6, 7, 8, 9)
Df2 = c(1, 2, 3, 4, 5)
Df3 = c(10, 11, 12, 13, 14)
Df4 = c(15, 16, 17, 18, 19)
A <- data.frame(Df1=5:9,
Df2=1:5,
Df3=10:14,
Df4=15:19
)
print(A)
## Df1 Df2 Df3 Df4
## 1 5 1 10 15
## 2 6 2 11 16
## 3 7 3 12 17
## 4 8 4 13 18
## 5 9 5 14 19