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
15 views

How to generate grouped stacked barplot with ggplot?

I am trying to generate a grouped stacked barplot in ggplot. My grouped variable is "person" . Here is my script : v1 person variable value cat 1 A value1 100 a1 2 A value1 ...
0
votes
0answers
12 views

How to change the x-labels in a plot with time series data by months like“201801” “201802”?

The first 6 rows of the data set is like this time loan invest sales 1 200801 8058 1186.860 232.3790 2 200802 2434 1186.860 205.1219 3 ...
0
votes
0answers
15 views

Rounding all numbers in r with no decimals

I'm just starting out in R and I'm trying to round all the numbers with no decimals in my data frame, preferably when I'm reading in a file. I've looked up several ways to round decimals, but it is ...
0
votes
1answer
14 views

Converting set of rows into column in R [duplicate]

I have a data set containing information regarding morphological traits of individuals of several species. Columns are about the individual id, species' name, trait types and trait values. I need to ...
0
votes
0answers
12 views

How to get the indexes of the K nearest neighbors of an observation that is not within the data frame in r?

Suppose I have this data frame: df <- data.frame(replicate(10,sample(1:25,1000,rep=TRUE))) I also have this observation which is not in the dataset. obs <- c(12, 2, 19, 3, 5, 8, 12, 4, 5, 1) ...
0
votes
1answer
26 views

need help displaying every 10th year on x axis ggplot graph

Need help plotting every 10th year on the x axis. temp_carbon %>% select(Year = year, Global = temp_anomaly, Land = land_anomaly, Ocean = ocean_anomaly) %>% gather(Region, Temp_anomaly, ...
0
votes
0answers
15 views

Quickly calculate Euclidean distance between many long vectors in R

I would like to calculate the Euclidean distances between many (100) vectors of the same length (about 1000) that are all in one dataframe, and then store the results in a symmetric matrix where the (...
2
votes
0answers
20 views

how to ignore case in sep argument for tidyr::separate()

If I want to separate a string into a few new columns based on a letter, how can I ignore the case of that letter? regex("h", ignore_case = TRUE) is not working in tidyr::separate() and the string is ...
0
votes
0answers
9 views

Simulate ARIMA model is different from resut from auto.arima in R

How do I simulate an ARIMA model of a given order and test the same model for the same order usingauto.arima()`. Example set.seed(123) n <- 10 # white noise: wn <- ts(rnorm(n)) # initialise ...
0
votes
0answers
14 views

How to count in Rselenium by using class?

<span class="audience-reviews__score"> <span class="star-display"><span class="star-display__filled "> </span><span class="star-display__filled "> </span><span ...
0
votes
1answer
28 views

R is returning false with == when the two paramaters are true [duplicate]

Here I have a 3 x 3 matrix and have calculated the determinant of the matrix and the determinant of the transpose of the matrix (which should be and are the same according to the code) but when ...
0
votes
1answer
24 views

Is there an R function for sumproduct the last 4 rows in a dataframe?

I need a function like sumproduct (excel) but only for the last 4 rows. Im using dplyr and i tried sumproduct with rollapply but i can only sum the last 4 rows of one column while i need multiply 2 ...
0
votes
1answer
22 views

Merging data giving numeric error when running code

I am trying to merge datasets together using RStudio and I am receiving. Is there anywhay to get the two to be read properly? The data source is from http://archive.ics.uci.edu/ml/machine-learning-...
0
votes
0answers
29 views

how to apply lag and lag rolling mean multiple columns

How to apply lag and lag rolling on multiple columns in a easy. I can apply on single by single column but I need apply on many columns more efficiently ppt <- ts(rep(c(5,6,7,8,11,13,14,15,16,15,...
-2
votes
0answers
12 views

Generate lognormally distributed numbers in R [duplicate]

I need to generate lognormally distributed numbers between 50,000 and 1,000,000 in R. What function would I use for this? Thanks!
-3
votes
0answers
27 views

I'm having trouble with working with data frames, specifically the Titanic data set

This is the problem I am working with and I have no clue how to make this into a function that returns the percentage of survival rates of the classes.
0
votes
2answers
22 views

R: compute the length of text data in a column

I have the following csv data myData: name attribute 1 Name1 attr11,attr12,attr13 2 Name2 attr21 3 Name3 attr31,attr32 I want to plot the distribution of the number of attributes, to do ...
0
votes
0answers
15 views

Isssue with height and matrix on R barplot

I have the following code and want to plot a barplot for the missing number of missing data(3) but keep getting an error: height' must be a vector or a matrix Any suggestions? bar_graph_genes &...
0
votes
0answers
18 views

how to change spacing in r bookdown

Could you please help me adjust the spacing in r bookdown. The bookdown guide is very vague about it and I could not find anything concrete. Here is my YAML: title: "Title" author: "Nxxx" date: "`...
1
vote
2answers
33 views

How to search a list of strings and remove all extra characters based on a list of names?

I have a data frame with a list of titles and other info, as well as a corresponding list of names. What I would like to do is extract the names from the titles and add them in a new column ("Players)...
0
votes
1answer
22 views

linear interpolation in r: replace NA in one column based on the data from another column

I have two variables here (x and y). I need to replace the NA in y, based on both x and y, using linear interpolation. The sample data is: df <- data.frame(x = c(1,1.15,1.20,1.75,1.83,1.86,1.95),y ...
0
votes
2answers
41 views

How to group_by and summarize multiple variables using regex?

I want to use regex to identify the variable to use to group_by and to summarize my data with one step. I cannot do separately because I have a large number of variables to summarize and the variable ...
2
votes
1answer
23 views

Unable to install plotly in r studio

When I run plotly in my r studio, I got the following error ** libs clang -I"/Library/Frameworks/R.framework/Resources/include" -DNDEBUG -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX....
0
votes
0answers
12 views

Legend for GGPlot Grob

library(ggplot2) library(gridExtra) data(iris) iris$group=sample(0:1,rep=T) g1 = ggplot() + geom_line(data=subset(iris, group == 0, Species == "setosa"), aes(Sepal.Length, Sepal.Width), color = "blue"...
-1
votes
0answers
14 views

How to simulate an ARIMA model and test same with auto.arima to be what I simulated

I am using auto.arima a function of forecast package in R. Whenever I simulate an ARIMA model and want to test the model I simulated with auto.arima() function, It gives me different model from what I ...
-2
votes
0answers
5 views

Flex Dashboard Knits Some Times

Hi, all here is a sample flex dashboard I've made for learning purposes. However, for some reason at times only the sliders part is evident and not the visualization. Is there a reason for this? Do I ...
0
votes
0answers
9 views

knit HTML tables to powerpoint or ioslides from Rmd

I am trying to knit output from the formattable package into slides. I have tried beamer, slidy, ioslides, and powerpoint, but each one renders the table badly in its own special way. Knit to HTML ...
3
votes
3answers
52 views

Rename a dataframe Column with text from within the column itself

Given a (simplified) dataframe with format df <- data.frame(a = c(1,2,3,4), b = c(4,3,2,1), temp1 = c("-","-","-","foo: 3"), temp2 = c("-","...
-3
votes
0answers
31 views

How to take the mean in a dataframe by quarters?

I have a dataframe with 213 rows and 2 columns (Date and Probability). Thanks to a previous post I am able to reduce the number of rows by grouping the Date by quarters. The problem is that, now, the ...
-4
votes
0answers
11 views

How to identify observations that have the same value for one string variable and different values for another?

I'm working with some data on NFL players. I'm merging two datasets. One dataset, called ADP, has player names in it. The other, stats, has player names and a unique identifier "id" for each player. ...
-4
votes
0answers
14 views

Heatmap of binary factor: proportion of one level

I have two numerical features and one binary factor. My goal is to create a heatmap where the heat is given as the proportion of one level to the total number of observations. Is anyone aware of an ...
0
votes
0answers
18 views

Which is more efficient in Stan?

Is it more efficient to declare a transformed parameter in the transformed parameters block or in the model block if I do not require the transformed parameter to be returned in the output. For ...
0
votes
0answers
6 views

Using rmarkdown. Build a model using “neuralnet::neuralnet()”, when applying the plot function, the output plot is some how incomplete. Any fix?

Using rmarkdown. Build a model using "neuralnet::neuralnet()", when applying the plot function, the output plot is some how incomplete. Any fix? It's both the cases in the rmarkdown and in the ...
-3
votes
0answers
23 views

Can`t install R 3.6.1 correctly in Ubuntu

Primarily I have had R 3.6.1 but decided to install earlier version with purpose of using some population genetics packages unavailable in R 3.6.1. I didn not know how to downgrade the version, so I ...
0
votes
1answer
23 views

How to use regular expression to extract the byte like '<9f><98><82>' from a string in the R

I am trying to use r to extract a code like '<9f><98><82>' in order to get the emoji code in a string using R and regular expression but not successful as there are multiple <> in the ...
1
vote
1answer
32 views

mapping functions over a list of data frames

I am trying to apply a series of functions to my data, however I am going wrong a little bit. The functions can create more than one column so I use bind_rows to add them to the original data. What ...
0
votes
1answer
18 views

matrix condition inside the while loop

Consider the following toy example: set.seed(10) (n <- sample(5,size=1)) (d <- matrix(sample(1:100, size = n), ncol=1)) (g <- matrix(sample(1:10, size = n), ncol=1)) i <-1 while(d>g){ ...
0
votes
1answer
20 views

Change recursive vector to atomic vector for t-test

I'm new to R and am trying to run a t-test for two means. I keep getting the error is.atomic is not TRUE. I know I need to make my data atomic, but I haven't found a way online. I've ran code to ...
-3
votes
0answers
17 views

Lineal Model with qualitative data (Factors Class)

I'm trying to do a lineal model with a quantitative data. I already change the class of the values from character to factor. I already change the class of the values from character to factor. But ...
0
votes
0answers
9 views

Travis build failed: Error in library(RSelenium) : there is no package called ‘RSelenium’

I'm trying to add travis in my R package repository, which depends on RSelenium package, but the build keep failing when try this: 'library(RSelenium)'. I've already tried to install the package ...
2
votes
1answer
22 views

Shiny Plot Height behaving different on different desktop

I am trying to make a custom UI in which i have to plot 4 plots inside each tab, but i am getting scroll on plot rendering and when i add height as 240 scrollbar disappear and it works for the same ...
1
vote
2answers
51 views

How to use mutate to create multiple variables with regex

I want to create new variables using paste0 by performing operation on other variables also using paste0. My approach fails as it only pastes the names of the new variables as observations, without ...
1
vote
2answers
41 views

How to name an element in a loop?

I am making a list of 76 components means, ranging from 0 to 0.75. I would like to know how to name the component dynamically. For example, I'd like to name the component lis_0,lis_0.01,lis_0.02 and ...
-1
votes
1answer
22 views

How to convert an object to data.frame?

I need a data.frame for some analysis. The origin of the data is a CSV file, which I have imported into R with the following code presa_preparado <- read_delim ("presa_preparado.csv", ";", ...
0
votes
1answer
28 views

How to find the outliers for two columns in data frame

I need to get the total number of outliers for variable1 for each type of variable2 and variable 3 and then show it in a table. It also needs to show only cases where variable4 is larger than 1.5. I ...
-5
votes
0answers
28 views

How to create new columns to get carry over effect

Need new columns of many measures the calculation is done in excel. I need to apply in R:
0
votes
0answers
9 views

Shiny app session cookie is not found the first time

I am using cookies in my shiny app. But there is the problem that after a cookie is set in the browser and the page is refreshed, the cookie is not found at first. You can see this in the example app: ...
0
votes
2answers
15 views

adjust distance between geom_text and bars with ggplot

I have a plot that present correlation values, and I am representing a significant correlation with a star on each bar. However, I cannot seem to increase the distance between the star and the bar, as ...
0
votes
1answer
14 views

Why is flexsurvreg failing in this painfully simple case?

Behold the painfully simple case and the error(s). Comments inline. library(flexsurv) #> Loading required package: survival library(tidyverse) library(magrittr) #> #> Attaching package: '...
0
votes
3answers
44 views

Converting code from base R to dplyr, specifically adding a variable

I am trying to add a new variable called "state_color" to the data set "birth_data." I want to streamline my code with dplyr, but I am unsure of how to convert it. I know that in base R it would look ...