我正在尝试在R中绘制一些数据点.我目前正在使用ggplot2(但我对备用软件包的建议持开放态度).问题是图表渲染时间太长(通常超过一分钟).我正在寻找方法来更快地实现这一点 - 理想的实时.我将不胜感激任何帮助 - 为了清楚起见,将代码附加到问题上.
使用~500000个数据点创建(随机)数据框:
letters <- c("A", "B", "C", "D", "E", "F", "G")
myLetters <- sample(x = letters, size = 100000, replace = T)
direction <- c("x", "y", "z")
factor1 <- sample(x = direction, size = 100000, replace = T)
factor2 <- runif(100000, 0, 20)
factor3 <- runif(100000, 0, 100)
decile <- sample(x = 1:10, size = 100000, replace = T)
new.plot.df <- data.frame(letters = myLetters, factor1 = factor1, factor2 = factor2,
factor3 = factor3, decile = decile) …Run Code Online (Sandbox Code Playgroud) 所以我最近开始使用R并且该apply()功能正在绊倒我.我很感激这方面的帮助:
is.numeric(iris$Sepal.Length) # returns TRUE
is.numeric(iris$Sepal.Width) # returns TRUE
is.numeric(iris$Petal.Length) # returns TRUE
is.numeric(iris$Petal.Width) # returns TRUE
Run Code Online (Sandbox Code Playgroud)
但,
apply(iris, 2, FUN = is.numeric)
Run Code Online (Sandbox Code Playgroud)
回报
Sepal.Length Sepal.Width Petal.Length Petal.Width Species
FALSE FALSE FALSE FALSE FALSE
Run Code Online (Sandbox Code Playgroud)
这是怎么回事?
我正在构建一个R包(我们称之为"pkg"),并希望编写一个从Internet下载文件并将其保存在我的包目录中的"inst/extdata"目录中的函数.
download_file <- function(link) {
path <- ... # path to where "pkg" is stored
# something along the lines of ....../pkg
download.file(link, paste(path, "inst/extdata", "newfile", sep = ""))
}
Run Code Online (Sandbox Code Playgroud)
你能帮助我找到"路径"吗?在开发包时,我可以做"getwd()" - 但是,当用户调用我的包时,她的工作目录可能不是pkg目录.在这种情况下,如何获取程序包目录的路径?