David Resch
David Resch

Reputation: 113

Convert Array to dataframe

I have the following array and I would like to convert it to a dataframe with the column names(Time and DepressionCount). I am pretty much a complete beginner to R and some help is greatly appreciated.

2004 2004.25 2004.5 2004.75 2005 2005.25 2005.5 2005.75
 875     820    785     857  844     841    726     766

Upvotes: 4

Views: 8312

Answers (1)

Math
Math

Reputation: 2436

This is what you want:

dd=data.frame(t(array))
colnames(dd) = c("Time", "DepressionCount")

t(array) changes the two lines array into a two columns array, data.frame simply converts the array to a data.frame and colnames changes the column names of the data.frame.

Upvotes: 4

Related Questions