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)
To remove line numbers from data. table object in R, we can set row. names to FALSE and print the data. table object.
To display ( or print) a text with R, use either the R-command cat() or print(). Note that in each case, the text is considered by R as a script, so it should be in quotes. Note there is subtle difference between the two commands so type on your prompt help(cat) and help(print) to see the difference.
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.
Something like this should work:
apply(l, 1, function(x){cat(x); cat("\n")})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With