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.

Filter by
Sorted by
Tagged with
0
votes
0answers
10 views

R: Save a data.table as an image with Title

A follow-up question to this: R save table as image Is there any way to add Custom Titles and Headings to images generated by the following code? library(ggplot2) library(gridExtra) df &...
0
votes
0answers
13 views

How can I scrape content from a website that's in Simplified Chinese?

I have tested this code on various English language websites with no problem. However, when I tried to scrape content from a website that's in Simplified Chinese, the data appeared as gibberish in the ...
0
votes
1answer
14 views

How to plot the grand mean of several lines plots across time using ggplot

I am trying to plot 35 individual time series data (102 data points each) using ggplot and geom_line. I'd also like to overlap the grandmean of the individual data across time as a second geom_line ...
1
vote
1answer
15 views

Logical Operator to delete Rows in data.frame

this is my data.frame: question<-structure(list(`250` = c(-3.87200118673366, -4.47389106649744, -4.02280403506916, -4.19939802488332, -3.47743162588758, -4.89573738026802, -4.67605723223933, -3....
0
votes
0answers
15 views

How to combine ggbarplot and ggscatter in the same plot?

I want to plot a figure that combines elements from ggbarplot and ggscatter to get output similar to the example below using ggpubr. Below I present my attempts, so far unsuccessful. Any help would ...
1
vote
2answers
17 views

R: loop through variable names in data.table using for-loop (and group them by variable)

> colnames(fileIWantToAnalyze) [1] "variable_1a" "variable_5b" [3] "variable_1b" "variable_6a" [5] "variable_2a" "...
1
vote
0answers
12 views

How to include a Surv object as a new column in a data.table?

I'm performing survival analysis, and I want to create a Surv object as its own column in a data.table. Although Surv objects are considered vectors, I can't use them to make new column since they are ...
1
vote
0answers
20 views

stringr install error: namespace ‘stringr’ is imported by ‘bibtex’ so cannot be unloaded

Hi i am trying to install the package stringr in my R. i tried following: install.packages("stringr") install.packages("stringr",dependencies = TRUE, repos = "http://cran.us.r-project.org") ...
0
votes
0answers
9 views

Is there a way to have different dropdown options for different rows in an rhandsontable?

I am making a shiny app where the user needs to select dropdown options in a table. I am using rhandsontable, however it seems like I am only able to have one set of dropdown options for a single ...
0
votes
0answers
12 views

Output of omegaSem not showing due to object not found

I'm folowing a tutorial to perform ω Mcdonald Omega and α Cronbach Alpha in R, in order to estimate reliability for a psychometric test. This is my first time using R. I usually work on SPSS for ...
0
votes
2answers
40 views

Transforming dataframes in R using apply [duplicate]

I am attempting to convert my dataframe from one format to another I stared with: >dfst cat1 cat2 cat3 a x 1 b x 2 c x 3 a y 9 b y 8 c ...
0
votes
1answer
28 views

dplyr::gather - getting error message but do not know why

I am getting this error: Error in gather(., key = "Capture", value = "Length", t1:t5, na.rm = TRUE, : could not find function "gather" I have called in dplyr, and had no previous problems with ...
0
votes
3answers
46 views

Make combinations in R

I want to make combinations of names from the same column (here, changing names to numbers for easier visual) Given the following data: Col1 1 2 3 4 5 6 How do I generate the following: Col1 ...
0
votes
0answers
20 views

Interactive visualization of euclideian distance with R

I would like to know if there is any way to visualize in an interactive way the process of euclidean distance with R. In a few words to recreate the plot below with a package that permits interactive ...
0
votes
0answers
15 views

Update an object in the background based on the information saved in a rhandsontable

I have built a tiny Shiny app. First, in the same folder as the app, I saved a list whose elements are tibbles with information about people (one table per person). The code for that (run it first): ...
0
votes
2answers
38 views

Make dataframe wide with months (columns) and periods (rows)

I have a dataframe with multiple columns of months and total (13 columns in total) and two periods (half a year, labeled as 1 and 7). I am trying to spread it wide and have it presented as January1 ...
0
votes
1answer
27 views

Returning data frames in the environment using lapply

This is probably a basic question, but I was trying to build a function that creates separate data frames in the environment. There is a similar question so I looked here thinking this was the answer,...
0
votes
0answers
23 views

How to fix stacked barplot on R?

I am doing microbiome research with percent abundances of respective taxa within various sequencing runs of a multi strain probiotic. For this project I need to construct a stacked barplot. How can I ...
1
vote
2answers
27 views

Select equal number of rows for levels in categorical variable based on level length

I have a 'master dataframe' with unequal observations for a categorical variable, and want to create, lets say, 20 other balanced sub-dataframes. For these new sub-datasets, I want to keep all rows ...
0
votes
0answers
7 views

R Windows: blotter package install for R 3.5.3 fails

I am having trouble installing blotter for R 3.5.3. I first tried > install_github("braverock/blotter") Downloading GitHub repo braverock/[email protected] Skipping 2 packages ahead of CRAN: foreach,...
1
vote
0answers
26 views

Puzzling behavior of arrange_at with .funs

I don't understand what dplyr::arrange_at is doing when passed a .funs parameter. For example suppose we create a data frame Z: library(dplyr) Z <- expand.grid(A = c(1:2, NA), B = c(1:2, NA)) ...
2
votes
2answers
44 views

Pass strings as code to summarize multiple columns with data.table

We would like to summarize a data table to create a lot of new variables that result from the combination of columns names and values from the original data. Here is reproducile example illustrating ...
0
votes
0answers
16 views

Delete label points and set hover text and legend in clustering scatter plot

I have the dataframe below : Val1<-c(0.5,0.7,0.8,0.9) Val2<-c(0.5,0.7,0.8,0.9) Val3<-c(0.5,0.7,0.8,0.9) Val4<-c(0.5,0.7,0.8,0.9) vales<-data.frame(Val1,Val2,Val3,Val4) row.names(vales)&...
0
votes
0answers
12 views

Animated plotly gauge plot with changing colors and text annotation

I have a gauge plot I want to animate (following this tutorial), with the color of the plot changing according to the current value. I also want an annotation* which displays the current value of the ...
0
votes
1answer
37 views

How to move data points into individual rows?

Data currently looks like this: Distance 0[] 1[.8] 2[.7 .5] 3[.8 .5 .2] 4[.4 .8 .8 .7] I want the following: .8 .7 .8 .4 .5 .5 .8 .2 .8 .7 Basically, first number in each row, then second, then ...
0
votes
0answers
13 views

Creating popups in Mapbox GL for Leaflet in R-Shiny?

I'm finding it impossible to add the popups that are possible to add in JS via R's Leaflet.MapBoxGL library. This library lacks native popup functionality. Can anyone give me some pointers on how I ...
0
votes
0answers
12 views

Use xml_find_all() on detailed tag name [duplicate]

I'd like to extract data from an XML document. The document has many generations, and many siblings have the same main tag name, but different secondary tag names. I can't figure out how to reference ...
-3
votes
1answer
40 views

Counting by year in R

I have a dataset with 3 years worth of data 2010, 2012, and 2013. There are three places where the data can be area x, y and z. How can I count how many of orders for each month of 2010 are in area x, ...
0
votes
1answer
29 views

How to split an ordered data frame into first half and second half multiple times in R

I would like to split my data frame into multiple halves based on the ordering of one column so that I can have a column containing "first half" and "second half". For example, I want the data to look ...
0
votes
1answer
39 views

How to randomly generate a date and time that take place after another date and time

I want to generate random POSIX date and times that are after another randomly generated date and time to make a simulated dataset but I'm struggling with getting it right. So far, I've learned ...
0
votes
0answers
31 views

Data is not being properly imported and neither variables being recognized in descriptive analysis

I'm folowing a tutorial to perform ω Mcdonald Omega and α Cronbach Alpha in R, in order to estimate reliability for a psychometric test. This is my first time using R. I usually work on SPSS for ...
1
vote
0answers
21 views

Rolling join in data.table is using wrong time zone

I am trying to join two data tables using a rolling join. My time/date stamps are POSIXct specified as eastern standard time zone (EST). During the join, values using GMT are instead retrieved, i.e.,...
0
votes
1answer
20 views

How to reverse a `recipe` from `recipes` package?

Suppose I am creating a recipe for my machine learning model, and I need to preprocess my outcome. How do I reverse preprocess my predictions? library(recipes) biomass <- biomass rec <- ...
0
votes
1answer
25 views

How can I use as.formula and paste to form equations [on hold]

I have a group of variables, for example, vars <- c("age", "gender", "city"). I need to fit a model: fit <- coxme(Surv(tt, st) ~ age + gender + city + (1|id), data = df). Everything works well. ...
0
votes
0answers
14 views

debugging long R package load time [duplicate]

I have written an R package with 5229 lines of code. When I call library(mypackage), it takes 1.3 seconds to load (confirmed using lineprof and profvis). Another package I've written, with 3000 lines ...
2
votes
1answer
21 views

How to find quantiles / p-value after bootstrapping a cor.test kendall

I am using R for my data analysis. I want to find the quantiles / p-value for bootstrapped correlation of two numeric vectors. After calculating the correlation (method = kendall) of the two vectors I ...
0
votes
1answer
19 views

R: Set data point size of PCA autoplot according to a value

I am using the autoplot function to make a PCA plot. This is the code: library(ggfortify) df <- iris[c(1, 2, 3)] autoplot(prcomp(df), data=iris, colour = "Species") I would like to use the iris[c(...
2
votes
2answers
29 views

Convert wide to long in two variables

I have a dataframe like this df= data.frame(a1 = c(1,2,3), a2 = c(4,5,6), b1 = c(1,2,3), b2= c(4,NaN,6), id = c(1,2,3)) I want to get id a measure1 b measure2 1 1 a1 1 b1 1 2 2 ...
0
votes
1answer
12 views

How to perform mann kendall trend test on multiple levels

I am working with station precipitation data. Each station has precipitation data for 60 years and there are 30 stations. I want to perform a Mann Kendall trend test on each station to see if there is ...
0
votes
2answers
33 views

Counting occurences with missing values

I need to count occurences within my dataframe but I am missing some values. I have a dataframe that looks like this: ID Year 18941 2015 56511 2010 58185 2016 66183 1999 18863 2003 26635 2002 ...
1
vote
1answer
11 views

osFixedDollar Producing Wrong Time Stamps Quantstrat R

I have a strategy where I sell VXX when F1.F2 Contango in The vix futures is greater than 9 and close the position when F1.F2 Contango is less than 2. I would like to apply the Fixed Dollar Function. ...
1
vote
1answer
17 views

Efficient way to update specific row in dataframe1 based on specific condition match with that of dataframe2

I have 2 data frames of unequal size and df1 has a comma separated values. df1 <- data.frame(col1=c("id1", "id2", "id3", "id4", "id5", "id6", "id7"), col2=c("1,2", "2", "1,2,3", "...
0
votes
2answers
38 views

How to turn character vector into data frame

My data looks something like this: 13 EDHEC Business School 14 Columbia U and IZA 15 Yale U and Abdul Latif Jameel Poverty Action Lab 16 Carnegie Mellon U 17 Columbia U As you can see some of ...
1
vote
2answers
41 views

How can I get this average in a dataframe?

I know my next question es very basic in R, but I'm new on this! I have a data frame with qPCR information. What I want to do is a new column with the ct average as a function of spraying, genotype, ...
1
vote
2answers
30 views

Extract cell with AND without commas in R

I'm trying to extract the city and state from the Address column into 2 separate columns labeled City and State in r. This is what my data looks like: df <- data.frame(address = c("Los Angeles, CA"...
1
vote
2answers
44 views

How to find substrings flanked by a specific character and replace with text of the same length in R?

In R, what is the best way of finding dots flanked by asterisks and replace them with asterisks? input: "AG**...**GG*.*" desired output: "AG*******GG***" I tried the following function, but it is ...
-1
votes
0answers
12 views

NA/NaN/Inf in foreign function call (arg 5) from glmregNB in mpath

I am trying to fit a negative binomial glm using lasso with glmregNB. I found an answer that said this is most likely because of a tie and to use efron method, but that method isn't implemented for ...
0
votes
0answers
30 views

Can You Annotate with geom_bar (not based on a particular bar)

war_total %>% filter(Year == 2018) %>% top_n(60, wt = WAR) %>% ggplot(aes(reorder(Player, -WAR), WAR, fill = Position))+ geom_bar(stat = "identity", alpha = .7)+ scale_fill_manual( ...
0
votes
0answers
11 views

How to keep multi-line display while editing Shiny dataTable?

I have a dataTable in R Shiny (running the latest version 0.8). Each row contains a long, milti-line description. There is no problem while displaying the content in multiple lines. I am able to make ...
0
votes
0answers
9 views

Adapting weights for a glm() binomial regression

I've been facing a common problem. I can't use my dataset’s weights to estimate a binomial family model. I've been using the glm() function to estimate a probit model, but when my weights variable is ...