r

How to convert an ambiguous datetime column in data.table without using strptime?

左心房为你撑大大i 提交于 2021-02-19 02:15:04
问题 My data.table has a column with an "ambiguous" datetime format: "12/1/2016 15:30". How can I convert this datetime to a format R recognizes in a data.table without using strptime() and getting the warning message for initially converting to POSIXlt. The process works but the warning makes me think there is another way. My data table: my_dates <- c("12/1/2016 15:30", "12/1/2016 15:31", "12/1/2016 15:32") this <- c("a", "b", "c") that <- c(1, 2, 3) my_table <- data.table(my_dates, this, that)

Use dependencies in R packages through library() / Description file

余生长醉 提交于 2021-02-19 01:37:52
问题 I'm writing an R package that has several dependencies of other packages, some of them are available in CRAN and other ones are homemade. According to the help, library("my_package") will load the namespace of the package once I have previously installed it, i.e, install.package("my_package") . Nevertheless, once I have installed the package I am able to use all the functions of the installed but not loaded package through my_package::my_function() , so if my package has dependencies, beside

Use dependencies in R packages through library() / Description file

↘锁芯ラ 提交于 2021-02-19 01:37:48
问题 I'm writing an R package that has several dependencies of other packages, some of them are available in CRAN and other ones are homemade. According to the help, library("my_package") will load the namespace of the package once I have previously installed it, i.e, install.package("my_package") . Nevertheless, once I have installed the package I am able to use all the functions of the installed but not loaded package through my_package::my_function() , so if my package has dependencies, beside

Use dependencies in R packages through library() / Description file

那年仲夏 提交于 2021-02-19 01:37:06
问题 I'm writing an R package that has several dependencies of other packages, some of them are available in CRAN and other ones are homemade. According to the help, library("my_package") will load the namespace of the package once I have previously installed it, i.e, install.package("my_package") . Nevertheless, once I have installed the package I am able to use all the functions of the installed but not loaded package through my_package::my_function() , so if my package has dependencies, beside

R command dir.create and file.path

て烟熏妆下的殇ゞ 提交于 2021-02-19 01:34:51
问题 I've just started learning r and confused by the following question given in the course: Create a directory in the current working directory called “testdir2” and a subdirectory for it called “testdir3”, all in one command by using dir.create() and file.path(). I couldn't get it to accept my answer and then found another site online giving the answers. This is the answer the other site gave: dir.create(file.path('testdir2', 'testdir3'), recursive = TRUE) After copy/pasting this answer it

how to replace legend 'bullet' of geom_text guide (legend)

廉价感情. 提交于 2021-02-19 01:28:50
问题 I would like to replace the 'bullets' in legend (guide) of geom_text . Now it's a tilted a , but I would like a big fat circle or a square or any other shape that will emphasize the color (more). library(ggplot2) majdf <- data.frame(lvl = rep(c("A", "B"), each = 50), val = c(rnorm(50, 1), rnorm(50, 3))) majtxt <- data.frame(species = c("sp1", "sp2", "sp3"), geq = c(0.01, 2, 2.2)) ggplot(majdf, aes(x = val)) + geom_density() + geom_vline(data = majtxt, aes(xintercept = geq)) + geom_text(data =

Produce multiple ggplot figures within one ggplot()

有些话、适合烂在心里 提交于 2021-02-19 01:27:53
问题 I would like to use the same ggplot code to produce 8 different figures conditional upon figures in my dataframe. Usually I would use facet_grid, but in this case, I would like to end up with a pdf of each individual figure. For example, I would like one pdf for each row here: df <- read.table(text = " xvalue yvalue location planting crop 1 5 A early corn 2 3 A late corn 6 2 A early soy 7 4 A late soy 4 7 S early corn 2 6 S late corn 3 2 S early soy 5 1 S late soy ", sep = "", header = TRUE)

Add “title” to my factors using facet_grid

家住魔仙堡 提交于 2021-02-19 01:25:09
问题 I would like to add text / title for my factors using ggplot2. For exemple for data from {reshape2} library: library(reshape2) library(ggplot2) ggplot(tips, aes(x=total_bill, y=tip/total_bill)) + geom_point(shape=1) + facet_grid(sex ~ .) Factors labels are: Female and Male. How can I add above them the title "sex"? 回答1: Adapting this answer. Slightly better version. Work out its own width. library(reshape2) library(ggplot2) library(grid) library(gtable) p = ggplot(tips, aes(x=total_bill, y

Restart shiny app from within app (reloading data)

帅比萌擦擦* 提交于 2021-02-19 01:23:48
问题 I want to restart a shiny app from within the app, so that e.g. code in global.R will be executed again (to reload a csv file with data). Here is a minimal example showing what I want to do: This shiny app loads some coordinates data and plots markers on a map. When a new marker is added to the map, the new coordinates should be appended to the old data and saved as a csv file. Then the app should restart, load data.csv again, so all markers are shown on the map. I tried adapting code from

Restart shiny app from within app (reloading data)

亡梦爱人 提交于 2021-02-19 01:21:52
问题 I want to restart a shiny app from within the app, so that e.g. code in global.R will be executed again (to reload a csv file with data). Here is a minimal example showing what I want to do: This shiny app loads some coordinates data and plots markers on a map. When a new marker is added to the map, the new coordinates should be appended to the old data and saved as a csv file. Then the app should restart, load data.csv again, so all markers are shown on the map. I tried adapting code from