pmagunia
pmagunia

Reputation: 1798

Print list without line numbers in R

I would like to print a list in R without line numbers.

I tried the cat command but it doesn't work for lists.

Does anyone have any suggestions ?

    GROUP    SEX INCOME STATE    n  mean
11       1   Male      1    AL  159 26.49
12       2 Female      1    AL  204 26.64
13       3   Male      2    AL  255 27.97
14       4 Female      2    AL  476 29.06

Example data to use:

foo <- structure(list(GROUP = 1:4, 
                      SEX = structure(c(2L, 1L, 2L, 1L),
                                      .Label = c("Female", "Male"),
                                      class = "factor"),
                      INCOME = c(1L, 1L, 2L, 2L), 
                      STATE = structure(c(1L, 1L, 1L, 1L), .Label = "AL", 
                                        class = "factor"), 
                      n = c(159L, 204L, 255L, 476L), 
                      mean = c(26.49, 26.64, 27.97, 29.06)),
                 .Names = c("GROUP", "SEX", "INCOME", "STATE", "n", "mean"), 
                 class = "data.frame", row.names = 11:14)

Upvotes: 41

Views: 57103

Answers (2)

Gavin Simpson
Gavin Simpson

Reputation: 174813

Do you just want the argument row.names = FALSE? E.g.

> print(foo, row.names = FALSE)
 GROUP    SEX INCOME STATE   n  mean
     1   Male      1    AL 159 26.49
     2 Female      1    AL 204 26.64
     3   Male      2    AL 255 27.97
     4 Female      2    AL 476 29.06

where this is using the ?print.data.frame method.

Upvotes: 52

nico
nico

Reputation: 51640

Something like this should work:

apply(l, 1, function(x){cat(x); cat("\n")})

Upvotes: 5

Related Questions