Open In App

Convert an Object to a Table in R Programming – as.table() Function

Last Updated : 19 Jun, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

as.table() function in R Language is used to convert an object into a table.

Syntax: as.table(x)

Parameters:
x: Object to be converted

Example 1:




# R Program to convert 
# an object to a table
  
# Creating a vector
vec = c(2, 4, 3, 1, 2, 3, 2, 1, 4, 2
  
# Calling as.table() Function
as.table(vec)


Output:

A B C D E F G H I J 
2 4 3 1 2 3 2 1 4 2 

Example 2:




# R Program to convert 
# an object to a table
  
# Creating a matrix
mat = matrix(c(1:9), 3, 3)
mat 
  
# Calling as.table() Function
as.table(mat)


Output:

     [, 1] [, 2] [, 3]
[1, ]    1    4    7
[2, ]    2    5    8
[3, ]    3    6    9
  A B C
A 1 4 7
B 2 5 8
C 3 6 9

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads