Chen Shen
Chen Shen

Reputation: 1

Importing matrix csv data into R - how to convert into dataframe

I have a set of csv data that is saved in matrix format attached image is an example of the matrix I would like to load the data into R and have it stored as a data frame with x$Year,x$Death,x$ASMR. How would I be able to do that?

Thanks!

CS

Upvotes: 0

Views: 423

Answers (1)

dvantwisk
dvantwisk

Reputation: 561

I think you're just looking for read.csv() and then change the colnames. I am assuming your file is separated by commas.

x <- read.csv('matrix.csv', sep=',', header=T)
colnames(x) <- c('Year', 'Death', 'ASMR')

Upvotes: 2

Related Questions