left.just: left justify column(s)

Usage Arguments Examples

Usage

1
left.just(dataframe, column = NULL)

Arguments

dataframe
column

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (dataframe, column = NULL) 
{
    left.j <- function(x) {
        n <- max(nchar(x))
        return(sprintf(paste("%-", n, "s", sep = ""), x))
    }
    lj <- function(dataframe, column) {
        DF2 <- dataframe
        if (is.null(column)) 
            column <- names(dataframe)
        Q <- max(nchar(as.character(DF2[, column])))
        DF2[, column] <- left.j(as.character(DF2[, column]))
        if (is.character(column)) {
            col <- names(DF2)[which(names(DF2) == column)]
            names(DF2)[which(names(DF2) == column)] <- sprintf(paste("%-", 
                Q, "s", sep = ""), col)
        }
        else {
            if (is.numeric(column)) {
                col <- names(DF2)[column]
                names(DF2)[column] <- sprintf(paste("%-", Q, 
                  "s", sep = ""), col)
            }
        }
        return(DF2)
    }
    if (length(column) < 2) {
        if (!is.data.frame(dataframe)) {
            y <- as.character(substitute(dataframe))
            dataframe <- data.frame(dataframe)
            y <- if (y[1] %in% c("[", "$")) 
                y[2]
            else y[1]
            names(dataframe) <- y
        }
        DF3 <- lj(dataframe = dataframe, column = column)
    }
    else {
        if (!is.numeric(column)) 
            column <- match(column, names(dataframe))
        dat <- dataframe[, -c(column)]
        ndf <- colnames(dataframe)
        LIST <- lapply(column, function(x) lj(dataframe = dataframe[, 
            x, drop = FALSE], column = NULL))
        dat2 <- cbind(do.call("cbind", LIST), dat, checknames = FALSE)
        NAMES <- colnames(dat2)
        newloc <- match(ndf, Trim(NAMES))
        DF3 <- dat2[, newloc]
    }
    return(DF3)
  }

trinker/DIFdetect documentation built on May 31, 2019, 8:40 p.m.