r

Eigenvalues calculations in C-within-R codes

天大地大妈咪最大 提交于 2021-02-18 12:28:28
问题 I am writing R code which uses compiled C code. From "Writing R Extensions" document, I learned there are many R executable/DLL that can be called from C code. The header file ‘Rmath.h’ lists many functions that are available and its source codes are listed on the this website: http://svn.r-project.org/R/trunk/src/nmath/ I need to calculate singular value decomposition of many matrices, however I do not find subroutines which does this on the above website. (So I am assuming that Rmath.h does

Logarithmic scale plot in R

一笑奈何 提交于 2021-02-18 12:25:10
问题 I want to plot the clustering coefficient and the average shortest- path as a function of the parameter p of the Watts-Strogatz model as following: And this is my code: library(igraph) library(ggplot2) library(reshape2) library(pracma) p <- #don't know how to generate this? trans <- -1 path <- -1 for (i in p) { ws_graph <- watts.strogatz.game(1, 1000, 4, i) trans <-c(trans, transitivity(ws_graph, type = "undirected", vids = NULL, weights = NULL)) path <- c(path,average.path.length(ws_graph))

Knitr: one plot per .tabset in for-loop

旧时模样 提交于 2021-02-18 12:17:08
问题 Long story short, I'm trying to use knitr to dynamically create separate tabsets and render a plot within each tabset. Below is a description of my failed attempts. I would appreciate a solution, but I suspect I'm just not understanding the fundamental way in which knitr renders output. So if you could point me to resources or provide some conceptual guidance, that would also be appreciated. Dynamically creating the tabsets themselves is easy. Here is my .R file #' --- #' title: #' author: #'

R: could not find function “function (object, …) \nobject” in glm() and bestglm()

 ̄綄美尐妖づ 提交于 2021-02-18 12:12:43
问题 I was running a bestglm analysis from the package bestglm : res.bestglm <- bestglm(Xy = offermodel, family = binomial, IC = "BIC", method = "exhaustive") summary(res.bestglm$BestModel) Morgan-Tatar search since family is non-gaussian. and I started getting this error: Error in model.frame.default(formula = y ~ 1, weights = weights, drop.unused.levels = TRUE) : could not find function "function (object, ...) \nobject" I inspected my model data and it looks good -- the right classes, no

Plot SpatialLinesDataFrame with ggplot2

北城以北 提交于 2021-02-18 12:10:30
问题 I would like to plot a SpatialLinesDataFrame calling ggplot with function fortify . The problem I have when using fortify is that I get undesirable lines between my points. I think it has something to do with the plot order Here is an example of my data : Coords <- matrix(c(4095215,2303286,4095275,2303226,4095275,2303196,4095395,2303076, 4095425,2303076,4095485,2303016,4095485,2302896,4095545,2302836,4095545,2302806, 4095575,2302776,4095575,2302746,4095635,2302686,4095635,2302656,4095665

How can I compare two strings to find the number of characters that match in R, using substitution distance?

感情迁移 提交于 2021-02-18 11:37:30
问题 In R, I have two character vectors, a and b. a <- c("abcdefg", "hijklmnop", "qrstuvwxyz") b <- c("abXdeXg", "hiXklXnoX", "Xrstuvwxyz") I want a function that counts the character mismatches between each element of a and the corresponding element of b. Using the example above, such a function should return c(2,3,1) . There is no need to align the strings. I need to compare each pair of strings character-by-character and count matches and/or mismatches in each pair. Does any such function exist

Is there a faster way than fread() to read big data?

£可爱£侵袭症+ 提交于 2021-02-18 11:27:28
问题 Hi first of all I already search on stack and google and found posts such at this one : Quickly reading very large tables as dataframes. While those are helpfull and well answered, I'm looking for more informations. I am looking for the best way to read/import "big" data that can go up to 50-60GB. I am currently using the fread() function from data.table and it is the function that is the fastest I know at the moment. The pc/server I work on got a good cpu (work station) and 32 GB RAM, but

Does rmarkdown allow captions and references for code chunks?

…衆ロ難τιáo~ 提交于 2021-02-18 11:09:40
问题 Is there a trick for captioning and referencing a chuck of code in rmarkdown (not the result of running the code)? For example, how do I reference this block of code: ```{r blah} blah <- "blah" ``` I know that I can use \@ref(fig:theFig) or \@ref(tab:theTable) to get at fig.cap or caption (with kable) but I don't see a way to caption and reference the code itself. 回答1: This would be a great feature. And I think it is not integrated yet. Here is an approach that works for PDF documents and

What is the equivalent of Stata function inlist() in R?

有些话、适合烂在心里 提交于 2021-02-18 10:53:12
问题 Stata's inlist allows us to refer to the real or string values of a variable. I was wondering whether R has such a function. Examples: I want to choose eight states from the variable state (you can think this as column state in any dataframe where state takes 50 string values (states of United States)). inlist(state,"NC","AZ","TX","NY","MA","CA","NJ") I want to choose nine values of age from the variable age (you can think this as column age in any dataframe where age takes numerical values

Error using geom_density_2d() in R : Computation failed in `stat_density2d()`: bandwidths must be strictly positive

≯℡__Kan透↙ 提交于 2021-02-18 10:29:25
问题 In a attempt to make a test 2d density plot with ggplot2, I used the code snippet: ggplot(df, aes(x = S1.x, y = S1.y)) + geom_point() + geom_density_2d() and I got the error: "Computation failed in stat_density2d() : bandwidths must be strictly positive" My dataframe looks like this: > df transcriptID S1.x S1.y S2.x S2.y DQ459412 0.000000 0.000000 0.000000 0.000000 DQ459413 1.584963 2.358379 4.392317 3.085722 DQ459415 0.000000 0.000000 0.000000 0.000000 DQ459418 0.000000 0.000000 0.000000 0