Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Array to dataframe

Tags:

arrays

r

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
like image 840
David Resch Avatar asked Nov 01 '25 02:11

David Resch


1 Answers

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.

like image 189
Math Avatar answered Nov 03 '25 19:11

Math



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!