Newest r Questions

Q&A for professional and enthusiast programmers

REAL() can only be applied to a 'numeric', not a 'list' - predict.randomForest

I have a slight problem with predicting values of a randomForest model. I always receive a following message: Error in predict.randomForest(rFmodel, newdata = testFin, type = "response") : REAL() can ...

Passing arguments to dplyr summarize function

I am trying to use the summarize function within dplyr to calculate summary statistics using a two argument function that passes a table and field name from a connected database. Unfortunately as ...

RStudio Shiny and JavaScript communication issue

I would like to make a Shiny app which makes as much HTML div object as the lenght of selected the database, but there could be a communication problem between Shiny and JavaScript. I tried to use ...

How to sprintf vector of mixed types and strings up to n digits precision?

I have a vector consisting of mixed double precision values and very short strings of characters. I want to sprintf them, while showing results up to n digits. The problem is, I can't sprintf strings ...

Include link to local html file in DataTable in Shiny

I want to include a link to a local html file, which lives inside the www directory of my shiny app, inside a column in data.table. On click a new tab should open showing the html file. I've found ...

packages in R for logistic regression tree

Is there a package in R that has a procedure for logistic regression tree. And if so do you have examples of script and output from the procedures.

vertices' attributes are not written to file when using igraph package in R

I am using igraph in R to calculate some network centrality measures. Once the measures are ready, I want to write the graph into a file (say Pajek format) V(net)$deg_net <- degree(net, loops = F)...

Creating R packages based off python scripts

I exclusively use python to scrape data off the NCAA stats website for a few sports. However, for the majority of my model development and data analysis I use R. I was trying to figure out how to ...

dplyr: Downloading a file based on the values in every row of a data_frame

I am trying to download a file based on the values in the rows of a data_frame. Here is what the data_frame looks like: df_foo = data_frame( input_id = 1:10, file_name_id = 20:30 ) Here is an ...

How to put an API query into a gwidget?

I have a query which I've wrapped. I now want to put this in a GUI using gwidgets. I'm not sure how to, especially when it comes to svalues. I can build the window with buttons, but I'm finding it ...

How to create a stem-leaf plot in R from txt file?

I am BRAND new to R. I need help creating a simple stem-leaf plot in R. This is my data to create the stem-leaf plot. It is saved in an text file. THIS IS HOW I WANT MY STEM TO LOOK-LEAF LIKE. ...

Classification of random sample of text in R

I am experimenting with trained text classification in R and have adapted this example to my own data. I have tested the example against two folders of text files, one consisting of documents ...

Create new folder when number of files created reach a certain value in R

I have this code that produces at least 50000 files. I have found out that the code slows at about 15000 files produced. By accident, I deleted the folder and "put it back" after renaming it and the ...

One or more factor levels in the outcome has no data: ''

I would like to to a logistic regression with the caret train function on the following data.frame: lr_scaled <- structure(list(p1 = c(0.485563579637833, -0.616626170629997, -0.0250480996345426, -...

R shiny app: How to address specific shinyBS buttons across several tabs?

I have started writing a shiny app. What I want to achieve is loading a text file with a string in one line - like this: $ cat testdata.txt hello world If the text gets loaded, the vowels are ...

Does R incorrectly compute the chi-squared statistic for 2x2 tables with low cell counts?

I just noticed that for 2 x 2 tables where cells have low frequencies, even with the Yates correction, R seems to be computing chi^2 statistics incorrectly. mat <- matrix(c(3, 2, 14, 10), ncol = 2)...

Using timevis in R presentations

I'm trying to include an HTML widget created by timevis in an R presentation (.Rpres). I'm using: library(timevis) data <- data.frame(id = 1:4, content = c("Item one", "Item two","Ranged item",...

Using “global” variables in function given to apply. We could see them, but could not assign values

Consider the following R-code: i <- 10 j <- 0 m <- matrix(c(1,2,3,4,5,6), nrow = 3, ncol = 2, byrow = TRUE) apply(m, 1, function(x) { if(i > 0) j<-1 else j<-2 return <...

Automatic conversion from integer to numeric during integer calculation in R?

Here are two snippets: a = 1:1000000; res = as.integer(0); class(res) system.time(for (e in a) res = res + e ^ 2) class(res) ########################### fn1 <- function (N) { for(i in 1:N) { ...

Pheatmap Color for Specific Value

I am very new to R and recently I have been playing around with the pheatmap library to generate, well, heatmaps. My problem is that I want to color my heatmap in a specific way. I'll describe below: ...

How to get 10 first days for each month in R

I'm trying to generate a sequence with the first 10 days for each month from 2010 to 2016 in RStudio. I have tried this: seq(as.Date("2010/01/01"), as.Date("2016/12/11"), by = "day") and this ...

How to change order of results in ggplot legend? [duplicate]

I try to manually alter the order of species in the legend. By default, they come out alphabetically. I want them in a specific order with a given color. I've managed to make the color list by using ...

How to convert these regular url to wildcard url for using it in userscript match?

These are the two url http://onwatchseries.to/cale.html?r=aHR0cDovL2dvcmlsbGF2aWQuaW4veGVod3hra3Ywcnp0 http://onwatchseries.to/cale.html?r=aHR0cDovL2dvcmlsbGF2aWQuaW4vZjJtZHdnc204dThq I have tried ...

Sampling from arbitrary distribution in PHP

I'm trying to draw n random numbers from a non uniform arbitrary probability distribution. My initial problem was that I didn't know how to do this statistically. Now I have found a beautiful function ...

R ifelse with warning message “longer object length is not a multiple of shorter object length”

Suppose I have these two DFs. df1 <- c("A","B","C","D") #The problem is D (both DFs have a different number of rows) df2 <- c("A","B","Z") My goal is to create a new variable in df3 based on ...

nlme::gls Get ML estimates of the means, variances and covariances

I need to extract the maximum likelihood or REML estimates of the means, variances and covariances of continuous variables from a gls model produced by the "nlme" R package. The glsEstimate() function ...

Select range ID with the highest score using foverlaps in R

I would like to select the range ID with the greatest quantity taken from a separate column using foverlaps, in a setting where a value falls between overlapping ranges. Although I'm quite familiar ...

Extracting values of upper triangle by row order

I have the following matrix: mat <- matrix(1:16, 4, 4) > mat [,1] [,2] [,3] [,4] [1,] 1 5 9 13 [2,] 2 6 10 14 [3,] 3 7 11 15 [4,] 4 8 12 16 I ...

RCaller, thread handling, and a Java GUI

I am making a Java GUI to go with my colleague's custom made R package, IntramiRExploreR, which includes a function made to create an interactive graphic via igraph and IntramiRExploreR's ...

how to use ggplot facet to separate plots into sections of the x-axis

I have a 18x3 data.frame. I would like a similar plot as in ggplot: arranging boxplots of multiple y-variables for each group of a continuous x but I want the x-axis divided into two variables (y0 &...

How to create new columns in R based on value data?

I have a dataset, simplified version is as following: input <- data_frame(key=c(1,2),Color=c("Red,Green","Blue,Red")) input key Color 1 Red,Green 2 Blue,Red I want to use ...

R ggplot2 : alpha depending density value

I want to plot a density map of events in San Francisco. I need to display hexagons. I need hexagons's alpha to be close to 1 when the density is maximum and close to 0 when the density is minimum. My ...

Building a simple generative adversarial net with neuralnet in R

I am trying to reproduce the example given in Goodfellow, I. et al.: Generative Adversarial Nets The pseudocode is given on page 4 as "Algorithm 1". I am trying to rebuild it with the neuralnet ...

Arranging data for two facet R line plot

I am trying to make a two facet line plot as this example. My problem is to arrange data to show desired variable on x-axis. Here is small data set I wanna use. Study,Cat,Dim1,Dim2,Dim3,Dim4 Study1,...

Use of matplot type=“b” for comparison

I am trying to create a graph of comparison between three categories and how they have varied their values over time. However, I realize that I am systematically doing something wrong since instead of ...

Find rows of matrix which contain rows of another matrix

Suppose I have an m x n matrix M1 and an k x l matrix M2 with l <= n. I want to find all those rows in M1 that contain some row of M2 in it. For example consider the following situation: > M1 &...

How to compute the Durbin h-statistic in R? [on hold]

Is there a package to compute the Durbin h-statistic in R? I've got a version of an autoregressive linear model so I can't use the usual Durbin Watson statistic.

How to share a mallet model in R

I have faced a huge problem while working with Mallet R package. I trained a cool model and want to share it with my colleague, but how can I do it? Well, I found out the way to save it with mallet....

Remove zeros and doble comparison in pairwise condensed matrix

I'd like to create a specific pairwise comparison matrices using a data frames. For this I have: Data frame with 5 products (deltametrina,fipronil,imidaclopride,sulfluramida,tiametoxam) and 2 ...

Error in knn(trainDataX, validationDataX, trainingType, k = 3) : 'train' and 'class' have different lengths

i am learning how to use R program language. Now i am learning the pca technique, the question was to train a model with the knn technique and to find out which is the accuracy value for the training ...

In R - generate pairwise data.frame from all rows in data.frame

I have a data.frame called df with a 8 million observations on 4 columns: name <- c("Pablo", "Christina", "Steve", "Diego", "Ali", "Brit", "Ruth", "Mia", "David", "Dylan") year <- seq(2000, ...

Machine Learning Algorithm Approach in R

I have a data set (that I came up with) consists of the following observations and features to record user log activity over time. I would like to build a model that predicts (score) which user_id's ...

Add lollipop sticks for point plots

How do I (if possible) add lollipop sticks to point plots? For instance, plot(1:10, sin(1:10)) How do I add a vertical line (lollipop stick) from each of the ten points to the x-axis? Do I need to ...

How to put entire datatable onto html report? (or at least left align)

I have several wide tables that should fit onto an html report, but I don't know how to do it. Consider the following example. It's rather silly I know, because I could chop the digits off, but many ...

add one with arbitrary class-values

I want to add one arbitrary class-value column to the existing data set.As test(data set has 94 column) does not have a classification column, I want to add one with arbitrary class-values. This will ...

Return correctly the variables updated from a function in a loop

I put some code but the answer should be simple. My function (cut it shorter) 'results' should return 4 matrices. Shortly, it has a loop with a parameter 'i' inserted in the function 'matr' that ...

R change factor in a dataset

I have a data frame contr_factors, with 1932 rows and the following columns: state, unarmed, not_flee, white_victim, attacked. I want to change the factors in the data set and I wrote this code: ...

For loop substitute for Big data

I am having huge data that contains millions of records. I am just sharing subset of it. data<-structure(list(email_address_hash = structure(c(1L, 1L, 2L, 2L, 2L, 3L, 3L), .Label = c("...

How to make two-class classification with decision tree in R

I am trying to implement two-class classification for the two extracted feature set(Running and Hugging) calculated with wavelet correlation. The thing I am trying to reach is,what is the accuracy ...

R: How to Implement knn density estimate in R

I am trying to implement a knn density estimation for variable 'speed' from data set cars. I use K=4. I am not totally sure about how the knn density estimate function works and I am trying to learn. ...
Translating... 0%