-3

I have the data in the table form (not even a R table) and I want to transform (or input) it into R to perform analysis.

The table is a 3-way contingency table which looks like this: enter image description here

Is there a way to easily input this into R? (It can by any format as long as I can perform some regression analysis)

Or I need to manually input it?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
TYZ
  • 8,466
  • 5
  • 29
  • 60
  • Are you talking specifically about this image? Or what's your raw input going to be? I'm sure you can read the data in, but you'll likely have to reshape it to do any analysis with it. – MrFlick Jul 22 '14 at 21:42
  • This is exactly the data, it is given like this in a table, for any number or categorical name, I need to manually input by myself. – TYZ Jul 22 '14 at 21:49
  • So it is an image? Then you might want to track down some OCR software. – MrFlick Jul 22 '14 at 21:51
  • @MrFlick, for small tables like these `read.ftable` is pretty handy though. – A5C1D2H2I1M1N2O1R2T1 Jul 23 '14 at 07:31
  • Good point @AnandaMahto. I was thinking of only avoiding re-typing anything. – MrFlick Jul 23 '14 at 12:44

1 Answers1

7

In R, this is an ftable.

Inputting an ftable manually is not too difficult if you know how the function works. The data need to be in a format like this:

breathless yes no
coughed    yes no
age
20-24  9  7  95 1841
25-29 23  9 108 1654
30-34 54 19 177 1863

If the data are in this format, you can use read.ftable. For example:

temp <- read.ftable(textConnection("breathless yes no
coughed yes no
age
20-24  9  7  95 1841
25-29 23  9 108 1654
30-34 54 19 177 1863"))
temp
#       breathless  yes        no     
#       coughed     yes   no  yes   no
# age                                 
# 20-24               9    7   95 1841
# 25-29              23    9  108 1654
# 30-34              54   19  177 1863

From there, if you want a "long" data.frame, with which analysis and reshaping to different formats is much easier, just wrap it in data.frame().

data.frame(temp)
#      age breathless coughed Freq
# 1  20-24        yes     yes    9
# 2  25-29        yes     yes   23
# 3  30-34        yes     yes   54
# 4  20-24         no     yes   95
# 5  25-29         no     yes  108
# 6  30-34         no     yes  177
# 7  20-24        yes      no    7
# 8  25-29        yes      no    9
# 9  30-34        yes      no   19
# 10 20-24         no      no 1841
# 11 25-29         no      no 1654
# 12 30-34         no      no 1863
A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485