1

Problem I started with an ungrouped data set which I proceeded to group, the output of the grouping however, does not return all 427 rows. The output is needed to input that data into a table.

So initially the data was ungrouped and appears as follows:

Occupation Education Age Died
1  household Secondary  39   no
2    farming   primary  83  yes
3    farming   primary  60  yes
4    farming   primary  73  yes
5    farming Secondary  51   no
6    farming iliterate  62  yes

The data is then grouped as follows:

occu %>% group_by(Occupation, Died, Age) %>% count()##use this to group on the occupation of the suicide victimrs

which gives the following output:

 Occupation       Died    Age     n
  <fct>            <fct> <int> <int>
1 business/service no       20     2
2 business/service no       30     1
3 business/service no       31     2
4 business/service no       34     1
5 business/service no       36     2
6 business/service no       41     1
7 business/service no       44     1
8 business/service no       46     1
9 business/service no       84     1
10 business/service yes      21     1
# ... with 417 more rows

problem is i need all the rows in order to input the grouped data into a table using:

dt <- read.table(text="full output from above")

If any more code would be useful to solving this let me know.

rsteward
  • 51
  • 4
  • 2
    I'm not sure I get what you want, could you add the output you want please? – Gainz Aug 29 '19 at 14:30
  • Can't you apply `as.table()` to you `occu... ` line? No need to print to console and read again, r hopefully is smarter ;) – Chelmy88 Aug 29 '19 at 14:31
  • So i'd like the exact same output given above but with all 417 rows if possible – rsteward Aug 29 '19 at 14:32
  • 2
    It is a print options output. It can be changed in the options for tibble printing. Check [here](https://stackoverflow.com/questions/23188900/display-print-all-rows-of-a-tibble-tbl-df) – akrun Aug 29 '19 at 14:33
  • so ive tried using as.table () and get the following error: Error in as.table.default(occu %>% group_by(Occupation, Died, Age) %>% : cannot coerce to a table – rsteward Aug 29 '19 at 14:34
  • 1
    Could you not simply do ``as.data.frame``? Otherwise if you really want to print all the table in the console, follow Akrun's link. – Gainz Aug 29 '19 at 14:42

1 Answers1

1

It is not really clear what you want but try the following code :

occu %>% group_by(Occupation, Died, Age) %>% count()
dt <- as.data.frame(occu)

It seems you simply want to convert the tibble to a data frame. There is no need to print all the output and then copy-paste it into read.table().

Also if you need you can save your output with write.table(dt,"filename.txt"), it will create a .txt file with your data.


If what you want is really print all the tibble output in the console, then you can do the following code, as suggested by Akrun's link :

options(dplyr.print_max = 1e9)

It will allow R to print the full tibble into the console, which I think is not efficient to do what you are asking.

Gainz
  • 1,721
  • 9
  • 24