r - Abbreviate a numeric vector when displaying it in the console -


i'd abbreviate numeric vector when displaying through r console. tried function ?abbreviate, not thing want. in fact want whole vector abbreviated, not each element of vector. in addition, want pass ... @ breaking position indicate goes on. how can make this?

x = 1:100 x 1, 2, 3, 4, 5, 6 ... 

try str().

x <- 1:100 str(x, vec.len = 2.5, give.head = false) # 1 2 3 4 5 6 ... 

but david arenburg makes suggestion cat(). here's function allows adjust length more precisely.

f <- function(x, n) cat(x[1:n], "...") f(x, 5) # 1 2 3 4 5 ... f(x, 9) # 1 2 3 4 5 6 7 8 9 ... 

update: in response comment putting text name of input before values, can adjust function follows.

f <- function(x, n) {     cat(substitute(x), head(x, n), if(n < length(x)) "...") }  stuff <- 1:100 f(stuff, 6) # stuff 1 2 3 4 5 6 ... f(stuff, 12) # stuff 1 2 3 4 5 6 7 8 9 10 11 12 ... 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -