我想在R中打印一个没有行号的列表。
我尝试了cat
命令,但它不适用于列表。
有人有任何建议吗?
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
要使用的示例数据:
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)
答案 0 :(得分:40)
你只想要论证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
这是使用?print.data.frame
方法。
答案 1 :(得分:4)
这样的事情应该有效:
apply(l, 1, function(x){cat(x); cat("\n")})