Hi
I would like to convert numbers into different categorical levels . For
example,
In one of column of a dataframe, there are numbers: 1,2,3, 4. How can I
cover them into "bottom", "middle", "high" , "top" in R codes?
Thanks,
JL
[[alternative HTML version deleted]]
___
Hi Jeremie,
Or assuming that the matrix will always contain strings:
tabify<-function(x,col_names=NULL) {
# convert NAs to "NA"
x[is.na(x)]<-"NA"
# if this matrix doesn't have any column names
if(is.null(col_names)) col_names<-LETTERS[1:ncol(x)]
# get the format argument for sprintf
tab_widt
Hello,
Many thanks to you all for the prompt reply. Thanks for sharing.
On Saturday, 12 Jun 2021 at 09:53, Jeff Newmiller wrote:
> Can't say this appeals to me, but sprintf would make a difference:
>
> apply(
> mat,1,
> function(x) {
> x[is.na(x)] <-""
> cat(paste(
Just FYI, Jeremie, you can do what you want fairly easily if you look at the
options available to print() and sprint().
You can ask NA conversion to be done here directly at print time:
print(mat, na.print="")
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[,10]
Jeremie,
i'm not totally sure i understand your desire. but, does this help?
mx <- max(nchar(mat), na.rm=TRUE)
apply(
mat,1,
function(x) {
x[is.na(x)] <-""
cat(sprintf("%*s", mx, x), "\n")
})
cheers, Greg
__
R-he
Can't say this appeals to me, but sprintf would make a difference:
apply(
mat,1,
function(x) {
x[is.na(x)] <-""
cat(paste(sprintf("%16s",x)),"\n")
})
On June 12, 2021 9:24:51 AM PDT, Jeremie Juste wrote:
>Hello,
>
>I'm trying to print a razor thin front-end
Hello,
I'm trying to print a razor thin front-end using just text matrices and
the command prompt.
I admit that it is a bit crazy, it seems to do the job and is very quick
to implement... Except that I don't know of to fix the layout.
I'm just seeking to map column names to a standard domain in
7 matches
Mail list logo