Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)

I am having a table and from that, I want to turn it into a data frame. However, when I tried the following:

as.data.frame(pred_table)

it returned something completely different. I would like a data frame that has the first column as name, the second titled x, the third y, etc. 

1 Answer

0 votes
by (108k points)

See in R programming, if you want to convert your table into data frame then, you can do something like this :

#Convert to dataframe

data <- as.data.frame.matrix(pred_table)

#Assign column names

names(data) <- letters[seq_along(data)]

#Convert rownames to column

data$names <- rownames(data)

#Remove row names. 

rownames(data) <- NULL

Browse Categories

...