VOOZH about

URL: https://www.geeksforgeeks.org/r-language/convert-an-object-to-data-frame-in-r-programming-as-data-frame-function/

⇱ Convert an Object to Data Frame in R Programming - as.data.frame() Function - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Convert an Object to Data Frame in R Programming - as.data.frame() Function

Last Updated : 15 Jul, 2025

as.data.frame() function in R Programming Language is used to convert an object to data frame. These objects can be Vectors, Lists, Matrices, and Factors.

Syntax: as.data.frame(object)

Parameters: 

  • object: Vector, Matrix, factor, or data frame

R - as.data.frame() Function Example

Example 1: Basic example of as.data.frame() Function in R

Output: 

$col1
[1] 1 2 3 4

$col2
[1] "a" "B" "C" "D"

$col2
[1] "hello" "Geeks" "for" "geeks"

 col1 col2 col2.1
1 1 a hello
2 2 B Geeks
3 3 C for
4 4 D geeks

Example 2: 

Output: 

$Time
[1] 1 2 3 4 5 7

$demand
[1] 8.3 10.3 19.0 16.0 15.6 19.8

attr(, "reference")
[1] "A1.4, p. 270"
 Time demand
1 1 8.3
2 2 10.3
3 3 19.0
4 4 16.0
5 5 15.6
6 7 19.8
Comment
Article Tags:

Explore