Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Convert chr array by row to mixed in R

this has been asked before but I don't seem to get it working. I have a three-dimenional array (Financial information ~ Year ~ Company). I created this array through the use of melt and acast. Doing so did however also change all the individual datatypes to chr, which I cant use for calculations. How can I convert the rows with numbers in them back to numeric, but not the rows with text in them? Can columns even have different datatypes?

Original data:

Price Quantity Company Year Industry
10    20       A       2010 IT
11    22       A       2011 IT
15    10       B       2011 IT

Restructured data:

[A]      2010  2011
Price    10    11
Quantity 20    22
Industry IT    IT

[B]      2010  2011
Price    NA    15
Quantity NA    10
Industry NA    IT

The mode is always chr. I want the mode to remain chr for the 3rd row (Industry), but change it to numerical for row 1 and 2.

Thanks.

Comments