Questions tagged [r]

R is a free, open-source programming language and software environment for statistical computing, bioinformatics, visualization, and general computing. Please provide minimal and reproducible example(s) along with the desired output. Use `dput()` for data and specify all non-base packages with `library()` calls. Do not embed pictures for data or code, use indented code blocks instead. For statistics related questions, use https://stats.stackexchange.com.

0
votes
0answers
5 views

error in $: object of type 'closure' is not subsettable

I got error "Warning: Error in $: object of type 'closure' is not subsettable" in this line for(i in 1:nrow(mydata)){ mydata$Tags[i] = as.character(subset(train, train$TagId == mydata$...
0
votes
0answers
3 views

obtaining result of a nested loop into a list of dataframes

Hello I am pretty new to R and my first post here, really struggling to get my head around assigning result of nested for loops into a list or matrix. Any help is much appreciated. I am trying to ...
0
votes
0answers
5 views

How to delete row in for loop function?

I want to delete the second row in every sheet in an excel file. Actually, i have done this. for (i in 1:5) {bulan=read_excel(file, sheet=sheet[i],skip = 2)} but it deletes the first 2 rows. ...
0
votes
0answers
4 views

starting h2o in R hangs

I've installed h2o in R and when I run the command: h2o.init() the R console completely hangs with no message at all being given. I have to restart R in order to get out of this. If I run java -jar ...
0
votes
0answers
4 views

Changing the font size of figure captions in RMarkdown pdf output

I would like to make the font size of all captions (figures and tables) in my R Markdown document smaller. I'm using bookdown. The final output is pdf and I'm working in R Studio. To load the picture, ...
0
votes
2answers
27 views

How to convert a integer 123033 to time 12:30:33 format in R

After I imported the text file into R, R omitted "0" in the time column. For example: Before import time | After import time 077250 | 77250 000002 | 2 Thus, unable to ...
0
votes
0answers
20 views

R - Shapiro Test in dnorm() with weird p-value

I'm trying to use shapiro.test() function in R to test if my data fits in a normal curve. For this, I'm looking to the p-value of the output, if it's bigger than 0.05, for example. However, when I ...
0
votes
0answers
13 views

Another case of needing something transcript-ed from SQL to R

select subjectname as "Subject name", string_agg(s.facultyname || '(' || pi.year || ')', '; ') as "Faculty(year)" from subjects d INNER JOIN path pi on pi.subjectID=d.subjectID INNER JOIN preference s ...
1
vote
1answer
13 views

Package-specific utils::news() not working in RStudio

I'm trying to bring up news for a package while in RStudio. While the default utils::news() works for generating the base R changelog in the built-in viewer, I can't get it to work for a specific ...
0
votes
0answers
13 views

How to have unique legends and common legends on same plot

I would like to put multiple plots on the same page. in total the plots are 24 and 3 sets of eight plots have a common legend. In addition, all the 24 have a common legend. So I would like to put all ...
0
votes
0answers
22 views

How to speed up a Rcpp double for loop

Since I am not an expert in C++ (or Rcpp) I was wondering if there are other / better ways to write this little function below, which uses 2 for loops to fill up a matrix based on the values of 2 ...
1
vote
0answers
19 views

Why is my numeric matrix being converted into a character matrix?

I am trying to build a predictive classification model using the Binary Logistic Regression and Penalized LASSO which eventually I will compare both models. The thing is that I am trying to understand ...
0
votes
0answers
7 views

How to solve json unclosed string error in UN comtrade

When I was using UN comtrade api offered online: https://comtrade.un.org/Data/Doc/api/ex/r, I encountered an error. I was sending multiple requests to get the data - it all worked fine but the for a ...
0
votes
0answers
5 views

Can the htmlwidgets::saveWidget in R overwrite a html save?

I'm trying to create a 'real-time' website where a Plotly graph is constantly updating on my index.html file. To do this, I've created a html of the Plotly graph in R, using the function below. ...
-1
votes
1answer
10 views

How to determine tuneLength of train function for fitting elastic net

I'm trying to fit elastic net using my data,sorry I can't able to share the data as it's client data. So I wrote following code model <- train( LnSales_x ~., data = dataReg, method ="glmnet", ...
1
vote
1answer
33 views

How to populate data based on date period

I need to populate data based on date period and change the column formation, so my data can be read by Qlik Sense, a business intelligence program. So i have data below with file name "axn". This ...
1
vote
1answer
16 views

Reference to cell in another worksheet

Is there any way to reference to a cell in another worksheet in package openxlsx - insert Excel formula? I haven't found it in the package documentation. Tried to do it like: writeData(wb, ...
0
votes
0answers
11 views

How to call value from multiple dropdown list value in R Shiny

I am trying to pass value from dropdown list but mylist has multiple value because it is the USA state so how can I pass value to my list? I pass value on #server with command input$e1 but it's no ...
0
votes
0answers
21 views

How to fix “no such files or directory” reason?

I was about to install a package. At first it displayed a warning: 'lib ="C:/Program Files/R/R-3.6.0/library"' is not writable. After I tried to create a directory file using "dir.create". Even ...
5
votes
3answers
40 views

how to slice data in lapply function

I want to arrange N ggplot (each one is facetted) on a grid with grid.arrange. library(tidyverse) library(ggplot2) library(gridExtra) plots <- lapply(unique(mtcars$cyl), function(cyl) { data ...
0
votes
0answers
20 views

grepl cannot handle unmatched parentheses [duplicate]

I am getting as input a string, and I need to check whether it contains a certain character. My expressions are sometimes unusual, like "[Diab", but they are in quotes. The way I try to do this is ...
-1
votes
0answers
27 views

How to set up a for loop in R

I am trying to set up an "for" sequence to generate objects with corresponding formula object in it. I am trying to use this for randomForest, and once I tried to apply them in for loop, none of my ...
0
votes
1answer
16 views

How to spatial join 2 spatial polygon data frames?

I'm new in R;) I have 2 SpatialPolygonsDataFrames that I want to spatially join. But I haven't found helpful info so far. So the 2 SpatialPolygonsDataFrames are exactly alike. Same shapes,extent,crs,...
-1
votes
1answer
26 views

Remove duplicates based on second column

I am trying to write a section of code that does a few things: 1) group dataset by ID 2) count the number of unique months in column data.month 3) remove all IDs that have less than 9 months 4) ...
2
votes
1answer
19 views

Extract time (given in AM/PM) from a character string in r

I want to extract time (along with AM/PM)present in character string into a list which can be rendered into selectizeInput. I went through other solution available on net but solutions were either too ...
0
votes
2answers
14 views

How can I choose the empty variable to create before using for in R

are many days that I have a doubt about the empty variable that I have to create before a for loop. I explain my problem: I created a for that makes me a url. It works correctly (I don't write the ...
0
votes
0answers
5 views

Web scrapping: log in

I want to sign into a webpage,then, read some nodes using R... I've tried some solutions as https://github.com/tidyverse/rvest/blob/master/demo/united https://www.biostars.org/p/297028/ I tried ...
-1
votes
0answers
12 views

replacing the age groups with an indicator array

Age_group Population_size 15-24 172675 25-34 123065 35-44 96216 45-54 92051 55-64 72159 65-74 54722 75-84 32185 what command ...
0
votes
1answer
17 views

how to combine the result as a data frame in case of vector

gender_value<-function(author){ au<-sub("([^,]+),\\s*(.*)", "\\2 \\1", author) r<-GET(paste0("https://genderapi.io/api?name=",au)) g<-content(r)$gender n<-c(au,g)} author("nandan,...
1
vote
0answers
32 views

R: C stack error when using recursive function - optimizing the code

I am trying to make a simple "model" of loss of an initial value based on a number of criteria, as seen in my code below: mtDNAlen = 16299 copies = 10 mito = 50 fraction = copies*mtDNAlen*0.75 Rounds ...
0
votes
0answers
24 views

How to pass parameters to a function that is the argument of another function

I have a function f(x, d), where x is the a vector of two variables (x1, x2) and d is a Nx2 matrix of points. f(x) is a distance function calculating some compount distance from x to all the points in ...
0
votes
0answers
19 views

Iterating through a list's items in quotes in R

I am trying to iterate items from a list, which have quotation marks in their names. So far I have managed the following: lm_uni1=matrix(nrow=100,ncol=2) for(i in 5:100){ #t1.port....
0
votes
1answer
17 views

On click expanding of rows of a data table in shiny application is not working, How to solve this

I have written a code to create a data table in shiny R which when I click the row of interest it should expand and show me the child rows. However this is working only for the last row of my data ...
0
votes
0answers
9 views

Formatting dgCMatrix & store it in data frame

In r,after doing elastic net regression I'm getting regression coefficient as a dgCMatrix coeff. The coeff looks like 7 x 1 sparse Matrix of class "dgCMatrix" 1 (Intercept) ...
0
votes
0answers
24 views

Weird double arithmetics in R [duplicate]

To reproduce: > 1 - 0.9 - 0.1 [1] -2.775558e-17 > 1 - 0.1 - 0.9 [1] 0 > 1 + (-0.9 -0.1) [1] 0 > 1 + -0.9 + -0.1 [1] -2.775558e-17 > 1 + (-0.9 + -0.1) [1] 0 > - 0.9 - 0.1 + 1 [1] 0 &...
0
votes
1answer
9 views

Read multiple rds models and use predict function in lapply?

I have bunch of models saved as .rds, after reading all models and I use the predict function in loop on test data, showing error on predict method, but using individual model is working. (model are ...
0
votes
0answers
9 views

Shiny dynamic radioButton

I want to create an app where the input choices are dependand on one another. I managed to realize that for 2 selectInput parameter, but now I need to integrate radioButton's and I am stuck. The plot ...
0
votes
1answer
25 views

Why sometimes assigments in R are by reference? [duplicate]

Sometimes when I work with R and I want to make a copy of a variable to keep it as is, and use it later to monitor changes, R does not copy the variable and all changes are applied to both of them. ...
0
votes
1answer
28 views

Plot multiple lines with different colors

I am trying to create a plot i has multiple lines (data series). Each of these lines is a category and I want it to have a unique color. How do I make each of these to lines have a unique color ? ...
3
votes
2answers
29 views

group by and find index of first non-zero in each group in data table

I have a data table in R, that looks like: city year target 1: NYC 2000 0 2: NYC 2000 1 3: NYC 2000 1 4: LA 2000 0 5: LA 2000 0 6: LA 2000 1 7: LA 2000 ...
2
votes
2answers
30 views

Translating from SQL to R

I currently have the following SQL query: SELECT sector, COUNT(sector) FROM clients GROUP BY sector ORDER BY COUNT(sector) DESC LIMIT 3; So I am trying to make a move to tidyverse from SQL ...
0
votes
0answers
10 views

RVEST: Sign in into a web failed

I want to sign into a webpage,then, read some nodes using R... I've tried some solutions as https://github.com/tidyverse/rvest/blob/master/demo/united.R Scrape password-protected website in R https:...
0
votes
2answers
26 views

reverse the name if it seperate by comma

If there is a first and last name is like "nandan, vivek". I want to display as "vivek nandan". n<-("nandan,vivek") result: [1] vivek nandan where first name:vivek last name:nandan this is ...
0
votes
1answer
11 views

Problem with sample_n(2, replace=F) in a list of data with some data's size less than 2

I need help with sample_n() in ‘dplyr’ in R: I have a list of data riskset[[1]], riskset[[2]],..., riskset[[1000]]), each element riskset[[i]] of the list is a data frame of observations, and I ...
0
votes
0answers
12 views

How do I matched two matrices for two columns [duplicate]

I have two matrices; One with UniProt IDs and corresponding log ratios for each protein and another with gene symbol matched to each UniProt IDs. How can I extract log ratios correspond to gene symbol?...
-2
votes
0answers
28 views

Levenshtein distance for large files using thread or parallelization approach using R [on hold]

I have 2 files of s1= 340 rows and s2= 241339 rows. Need help in executing it fast either by threading or any other approach. Tried with both the codes below, but its taking many hours, kindly help ...
0
votes
1answer
28 views

Combining overlapping groups to include in violin plot/box plot in R

I am struggling with the following code using the iris dataset. I would like to draw a violin plot, only including setosa species, and do some complex overlapping combinations on subgroups of data. ...
0
votes
0answers
10 views

Error in make.names(fldnms, unique = TRUE) : invalid multibyte string 3

I am trying to import a shapefile in R afer importing csv file. Csv file is getting imported successfully. Links are provided for a similar type of error and they are not much clear. I tried to solve ...
0
votes
0answers
21 views

sample function gives different result in console and in knitted document when seed is set

I'm creating a document in a Rmarkdown file and knitting to HTML for file submission. Generating seeded samples using the sample function provide different results in the console and the knitted file. ...
-2
votes
0answers
27 views

Graphing a plot

What is the maximum value of function f(x) = xexp(-x2)+xsin(x) when x varies between 5 to 10? eq = function(x){x*exp(-2*x+x*sin(x))} plot(eq(5:10), type='l') I've tried plotting this in R: eq = ...

http://mssss.yulina-kosm.ru