Signup/Sign In

Answers

All questions must be answered. Here are the Answers given by this user in the Forum.

Two quick suggestions:

Use Gabor's batchfiles which are said to comprise tools helping with e.g. this bulk library relocations. Caveat: I have not used them.

Don't install libraries within the 'filetree' of the installed R version. On Windows, I may put R into C:/opt/R/R-$version but place all libraries into C:/opt/R/library/ using the following snippet as it alleviates the problem in the first place:

***$ cat .Renviron # this is using MSys/MinGW which looks like Cygwin
## Example .Renviron on Windows
R_LIBS="C:/opt/R/library"
***
3 years ago
Perhaps table is what you are after?
***dummyData = rep(c(1,2, 2, 2), 25)

table(dummyData)
# dummyData
# 1 2
# 25 75

## or another presentation of the same data
as.data.frame(table(dummyData))
# dummyData Freq
# 1 1 25
# 2 2 75***
3 years ago
Here's the simplest one I could come up with:

**dt[is.na(dt)] <- 0**

It's efficient and no need to write functions and other glue code.
3 years ago
alarm()

The alarm function. It works by sending **\a** to the console
3 years ago
try: **require("xtable")** or **"xtable" %in% rownames(installed.packages())**
3 years ago
Hence, you need to explicitly declare the columns names for the second data frame, **de**, then use **rbind()**. You only set column names for the first data frame, **df**:
***df<-data.frame("hi","bye")
names(df)<-c("hello","goodbye")

de<-data.frame("hola","ciao")
names(de)<-c("hello","goodbye")

newdf <- rbind(df, de)***
3 years ago
As pointed out by @DzimitryM, **percent()** has been "retired" in favor of **label_percent()**, which is a synonym for the old **percent_format()** function.

**label_percent()** returns a function, so to use it, you need an extra pair of parentheses.
***library(scales)
x <- c(-1, 0, 0.1, 0.555555, 1, 100)
label_percent()(x)
## [1] "-100%" "0%" "10%" "56%" "100%" "10 000%"***

Customize this by adding arguments inside the first set of parentheses.

***label_percent(big.mark = ",", suffix = " percent")(x)
## [1] "-100 percent" "0 percent" "10 percent"
## [4] "56 percent" "100 percent" "10,000 percent"***

An update, several years later:

These days there is a percent function in the scales package, as documented in krlmlr's answer. Use that instead of my hand-rolled solution.

Try something like
***percent <- function(x, digits = 2, format = "f", ...) {
paste0(formatC(100 * x, format = format, digits = digits, ...), "%")
}***
With usage, e.g.,
***x <- c(-1, 0, 0.1, 0.555555, 1, 100)
percent(x)***
3 years ago