相关疑难解决方法(0)

R中没有行号的打印列表

我想在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
Run Code Online (Sandbox Code Playgroud)

要使用的示例数据:

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, …
Run Code Online (Sandbox Code Playgroud)

r

29
推荐指数
2
解决办法
4万
查看次数

输出R,避免写"[1]"

print用来输出R中的函数,例如:

print("blah blah blah")
Run Code Online (Sandbox Code Playgroud)

这输出

[1] "blah blah blah"
Run Code Online (Sandbox Code Playgroud)

到控制台.我该如何避免[1]和报价?

r

27
推荐指数
3
解决办法
1万
查看次数

阻止print()输出R中的列表索引

我有一个包含六个图的列表,如下所示:

voi=c('inadist','smldist','lardist')

plist <- llply(voi, 
    function(v,df,s) {
        list(   
            assign(
                paste(v,'.violin'), 
                bwplot(groupname~df[,which(colnames(df)==v)]|fCycle*fPhase, 
                    data=df, 
                    groups=groupname, col=rainbow(1), box.ratio=3,
                    main=paste('Distribution of ', v, ' by Treatment and Cycle'),
                    sub=s, xlab=v, panel=panel.violin)),
            assign(
                paste(v,'.hexbin'),
                hexbinplot(df[,which(colnames(df)==v)]~starttime|groupname, 
                    data=df, xlab='Time(s)',main= paste('Distribution of ',v,' by Treatment'),
                    sub=s,ylab=v, aspect=0.5, colramp=redgrad.pal, layout=c(2,4)))

            )
    },data,meta$exp_name)
Run Code Online (Sandbox Code Playgroud)

如果我打印列表,print(plist)图表将输出到图形设备,然后将索引输出到控制台,结果如下:

[[1]]
[[1]][[1]]

[[1]][[2]]


[[2]]
[[2]][[1]]

[[2]][[2]]


[[3]]
[[3]][[1]]

[[3]][[2]]
Run Code Online (Sandbox Code Playgroud)

因为我正在编写一个webapp,我需要非常严格地控制控制台输出.到目前为止,我可以输出绘图而不输出索引的唯一方法是这样的:

for(p in plist) 
    for(i in p) 
        print(i)
Run Code Online (Sandbox Code Playgroud)

是否有更有效的方式来获得我需要的东西?

printing loops r list

5
推荐指数
1
解决办法
1543
查看次数

标签 统计

r ×3

list ×1

loops ×1

printing ×1