Thank you Lei. I incorporate Bill Dunlap's idea of flagging with FORTRAN
stars when field width is short. It works great and serves what I need.
Thank you all.
I love R!
Steven
Linus Chen 於 2019/7/23 下午 05:46 寫道:
Dear Steven,
The function "write()" has a parameter "columns".
And sprint() ca
Very nice indeed. Thank you gentlemen.
Steven
Michael Friendly 於 2019/7/24 上午 01:23 寫道:
Nice to see William Dunlap take the trouble to mimic the classic
Fortran behavior of printing for numbers that don't fit in the
given width :)
-Michael
On 7/22/19 6:33 p.m., William Dunlap via R-hel
Nice to see William Dunlap take the trouble to mimic the classic Fortran
behavior of printing for numbers that don't fit in the given width :)
-Michael
On 7/22/19 6:33 p.m., William Dunlap via R-help wrote:
The following mimics Fortran printing with format
F..
print1 <- function (x, perL
Thank you, Gentlemen. That serves my need. Bill's routine is great.
Also, Rui: Is there a way to get rid of the filled "NA" and use space
instead. Using fill = "" does not help either; it causes all numbers to
be embraced with quotations. Finally, I have no idea why Rui's message
did not reach
Dear Steven,
The function "write()" has a parameter "columns".
And sprint() can do do some formatting in C style.
x <- rnorm(100)
s <- sprintf( fmt="%8.2f" ,x )
write(s, file="", ncolumns=7L)
Cheers,
Lei
On Mon, 22 Jul 2019 at 07:37, Steven wrote:
>
> Is there a convenient way to print a vect
Hello,
How could I forgot na.print? Thanks, Bill.
This version c no longer has an argument fill and it's the one that
behaves more like the OP asks for so far.
print0c <- function(x, len = 10, digits = 2){
n <- length(x)
x <- round(x, digits = digits)
fill <- NA
m <- n %/% len
remai
By the way, the default print method has the argument 'na.print' that can
speciify how to print an NA value. E.g.,
> print(c(1234/, NA, 1), na.print="n/a")
[1] 0.1234123 n/a 1.000
> print(c(1234/, NA, 1), na.print="")
[1] 0.1234123 1.000
> print(c(1234/, NA, 1)
The following mimics Fortran printing with format
F..
print1 <- function (x, perLine = 10, fWidth = 8, fPrecision = 2,
fortranStars = TRUE)
{
format <- paste0("%", fWidth, ".", fPrecision, "f")
oldWidth <- getOption("width")
on.exit(options(width = oldWidth))
options(width = perLin
Simpler, no loops:
print0b <- function(x, len = 10, digits = 2, fill = ""){
n <- length(x)
x <- round(x, digits = digits)
m <- n %/% len
remainder <- n %% len
A <- matrix(x[seq_len(len*m)], ncol = len)
if(remainder > 0){
A <- rbind(A, c(x[(len*m + 1):n], rep(fill, len*(m + 1) - n
Hello,
Maybe something like the following is what you want.
I have added an extra argument 'fill' to allow to choose what to print
in the end. It's default value is "" making the entire matrix elements
characters but it can be NA or 0.
print0 <- function(x, len = 10, digits = 2, fill = ""){
Dear All:
Below is what I meant. Procedure print0 allows me to print a vector of
length 53 in four rows of 10 plus 1 row of 3 (Ido not like the NA). This
is silly. I am hoping that there is a candid way to print the matrix.
Thank you.
Steven Yen
===
n<-53; x<-runif(n); # x<-round(x,2)
print0
Is there a convenient way to print a vector into rows of a specified
column length? What I need is to print in the old FORTRAN format, viz.,
format(10F8.2)
which would print, for instance, a vector of 25 into two rows of 10 plus
an incomplete row of 5. I managed to write a procedure for that ta
12 matches
Mail list logo