r

Read QRcode from scanned document in R

*爱你&永不变心* 提交于 2021-02-20 15:30:07
问题 I am using the qrcode_gen() function from the qrcode package in R to generate a QR code, then place it on the top of a document (example linked below). The document is printed, written on, scanned, and stored as an image (.png) file. I would like to be able to read the QR code in R to get the imbedded text back. Eventually the whole process will be semi-automated in an Rshiny app, so I am hoping to keep everything in R , and not need to use an outside web tool to read the code. Has anyone

Zero based arrays/vectors in R

故事扮演 提交于 2021-02-20 15:02:02
问题 Is there some way to make R use zero based indexing for vectors and other sequence data structures as is followed, for example in C and python. We have some code that does some numerical processing in C, we are thinking of porting it over into R to make use of its advanced statistical functions, but the lack(as per my understanding after googling) of zero based index makes the task a bit more difficult. 回答1: TL;DR: just don't do it! I don't think the zero/one-based indexing is a major

Zero based arrays/vectors in R

无人久伴 提交于 2021-02-20 15:00:32
问题 Is there some way to make R use zero based indexing for vectors and other sequence data structures as is followed, for example in C and python. We have some code that does some numerical processing in C, we are thinking of porting it over into R to make use of its advanced statistical functions, but the lack(as per my understanding after googling) of zero based index makes the task a bit more difficult. 回答1: TL;DR: just don't do it! I don't think the zero/one-based indexing is a major

Saving networkD3 Sankey diagram using code only

无人久伴 提交于 2021-02-20 13:34:34
问题 I've created a Sankey diagram in R, using the networkD3 package, that I'd like to save as a static image, using code instead of clicking on 'Export' --> 'Save as Image...'. The current code I've tried (using this Sankey diagram as an example) is: library(networkD3) URL <- paste0( "https://cdn.rawgit.com/christophergandrud/networkD3/", "master/JSONdata/energy.json") Energy <- jsonlite::fromJSON(URL) # Plot jpeg( filename = "Sankey.jpg", width = 4000, height = 4000) sankeyNetwork(Links = Energy

Saving networkD3 Sankey diagram using code only

折月煮酒 提交于 2021-02-20 13:33:09
问题 I've created a Sankey diagram in R, using the networkD3 package, that I'd like to save as a static image, using code instead of clicking on 'Export' --> 'Save as Image...'. The current code I've tried (using this Sankey diagram as an example) is: library(networkD3) URL <- paste0( "https://cdn.rawgit.com/christophergandrud/networkD3/", "master/JSONdata/energy.json") Energy <- jsonlite::fromJSON(URL) # Plot jpeg( filename = "Sankey.jpg", width = 4000, height = 4000) sankeyNetwork(Links = Energy

Saving networkD3 Sankey diagram using code only

蹲街弑〆低调 提交于 2021-02-20 13:32:07
问题 I've created a Sankey diagram in R, using the networkD3 package, that I'd like to save as a static image, using code instead of clicking on 'Export' --> 'Save as Image...'. The current code I've tried (using this Sankey diagram as an example) is: library(networkD3) URL <- paste0( "https://cdn.rawgit.com/christophergandrud/networkD3/", "master/JSONdata/energy.json") Energy <- jsonlite::fromJSON(URL) # Plot jpeg( filename = "Sankey.jpg", width = 4000, height = 4000) sankeyNetwork(Links = Energy

Regression in R using poly() function

自闭症网瘾萝莉.ら 提交于 2021-02-20 10:11:20
问题 The function poly() in R is used in order to produce orthogonal vectors and can be helpful to interpret coefficient significance. However, I don't see the point of using it for prediction. To my view, the two following model (model_1 and model_2) should produce the same predictions. q=1:11 v=c(3,5,7,9.2,14,20,26,34,50,59,80) model_1=lm(v~poly(q,2)) model_2=lm(v~1+q+q^2) predict(model_1) predict(model_2) But it doesn't. Why? 回答1: Because they are not the same model. Your second one has one

Output graph to a two page PDF

↘锁芯ラ 提交于 2021-02-20 10:07:43
问题 I am doing a forest plot and want to save it to a PDF file. My forest plot is oversize (8in*20in). It can fit in a one page PDF like this: dev.print(pdf, file="C:\\Work\\plot.pdf", width=8, height=20); But then it is too long: When I print this PDF on a A4 paper, it has to be shrinked to fit the paper. So I want to save it to a two-page PDF file (from R). Ps: it is not a question about how to set the printer. How to do this? 回答1: So, you are able to generate an 8in x 20in == 203.2mm x 508mm =

How to use map() with possibly()

核能气质少年 提交于 2021-02-20 09:42:31
问题 I am using map() to get post data from Facebook using the following code: posts_data <- map(posts$query_id, getPost, token = fb_oauth, n = 1000) However, some of the query_id observations are incorrect, or are shared events, which the API cannot retrieve and gives me an error like: Error in callAPI(url = url, token = token, api = api) : Unsupported get request. Object with ID '1816137521765810_1832190963493790' does not exist, cannot be loaded due to missing permissions, or does not support

Using n() at the same time as calculating other summary statistics

我的未来我决定 提交于 2021-02-20 09:10:58
问题 I am having trouble to prepare a summary table using dplyr based on the data set below: set.seed(1) df <- data.frame(rep(sample(c(2012,2016),10, replace = T)), sample(c('Treat','Control'),10,replace = T), runif(10,0,1), runif(10,0,1), runif(10,0,1)) colnames(df) <- c('Year','Group','V1','V2','V3') I want to calculate the mean, median, standard deviation and count the number of observations by each combination of Year and Group . I have successfully used this code to get mean , median and sd :