# Questions tagged [r]

96774 questions

1

votes

2

answer

170

Views

### How to recognize data format - scraping in R

I am trying to use R to get data from an open data source in the Netherlands. The source is here.
When you open this in a browser (at least Chrome), it is presented as xml code. So I thought I can use the RCurl package to parse it, and then use XPath to extract the specific nodes I seek.
However, wh...

1

votes

1

answer

1k

Views

### Selecting hue/brewer colours manually in ggplot2

I am trying to produce progressive plots using the ggplot2 library in R.
What I mean by 'progressive' is that, for presentation purposes, I want to add lines to a plot one at a time, so I generate a single plot with many lines multiple times, each with an extra plotted line.
In ggplot2, using scale...

1

votes

1

answer

758

Views

### Cleaning data with R [closed]

I am new to R, but I am trying to manipulate data in a JSON format. I can get the data into by using Rstudio's import function, but I have having trouble converting it into a table. the string read like this.
'type': 'business',
'business_id': (encrypted business id),
'name': (business name),
'neig...

1

votes

3

answer

5.4k

Views

### convert a row of a data frame to a simple vector in R

I have a huge data frame from which I only select a couple of rows. Then I remove some of the columns based on a condition. let us say that I choose row 4460 as shown bellow:
V1870 V107 V1315 V1867 V1544 V1207 V1252 V1765 V342 V429 V1826 V865 V1374
4460 0 0 3 0 5 0 2 0...

1

votes

2

answer

1.6k

Views

### Parallel missForest

In the following example I am trying to use missForest to impute missing values. To speed up the process I used foreach package. In which i used 100 trees then I passed those trees to missForest function. Is this the right way to parallel missForest?
Here is example and what I have done:
library(...

1

votes

1

answer

1.4k

Views

### position_dodge with geom_errorbar

I have the following code
require(ggplot2)
pd

1

votes

1

answer

2.6k

Views

### How do I group similar strings in R? [closed]

I have a database with ~5,000 locality names, most of which are repetitions with typos, permutations, abreviations, etc. I would like to group them by similarity, to speed up further processing. The best would be to convert each variation into a "platonic form", and put two columns side by side, wit...

1

votes

2

answer

86

Views

### Conditionally apply a function on a row

I'm trying to do the following:
Evaluate a POSIXct class column in a data frame, if an observation is an even second do nothing, and if its an odd second add 1.
This is what I have so far:
df[,1]

2

votes

2

answer

21

Views

### Generate data.frame from frequency table

I have synthetic data in a 2*4 array with 500 observations:
datax = array(c(120, 181, 50, 43, 41, 33,24,8), dim=c(2,4))
dimnames(datax) = list(gender= c('male', 'female')
, punishment = c('None', 'Community_service', 'Youth_prison', 'Normal_prison'))
I'd like to produce a data.frame from the table t...

0

votes

2

answer

25

Views

### summarize from string matches

I have this df column:
df df
Strings
1 ñlas onepojasd
2 onenañdsl
3 ñelrtwofkld
4 asdthreeasp
5 asdfetwoasd
6 fouroqwke
7 okasdtwo
8 acmofour
9 porefour
10 okstwo
I know that each value from df$Strings will match with the words one, two, thre...

0

votes

0

answer

21

Views

### how to add streaks on barplot created with ggplot2

I used ggplot2 to create the following barplot. However, I would like to add stars to show the significancy between the dark and light for the same treatment. For instance SW.5 treatment.
calen_per

6

votes

0

answer

47

Views

### Why do logical vectors in RStudio View mode not show length?

Of the basic vector types, is there any special reason why the logical does not show its length?
View(list(1:10, rep(NA, 10), rep(1.0, 10), rep('x', 10)))

0

votes

2

answer

10

Views

### Can't find a solution to “Error in eval(predvars, data, env) : object `x` not found” when using rpart

I'm trying to run a relatively simple model in R such as fitTree

0

votes

0

answer

4

Views

### Accessing data via API in R

I'm trying to pull data on hospitals from www.phin.org.uk using R. The pages themselves are rendered in Javascript, so scraping looks painful.
I found that they have an API and think I managed to decipher it, although I am a complete beginner to APIs. Example code below.
library(httr)
> GET(url = "h...

2

votes

0

answer

24

Views

### What is the mutable part of an igraph object?

The igraph documentation mentions the "mutable" part of the igraph object.
I haven't been able to find a discussion of exactly what that is.
from the documentation
identical_graphs:
Decide if two graphs are identical
Description:
This is similar to identical in the base package, but ignores the mu...

1

votes

1

answer

252

Views

### Creating a network using R [closed]

I need to create an instance of a node using R, but I also need some attributes of the node to exist:
how many connections/links the node has (i.e. how many neighbors does it have)
what these connections are (for example if the node is 1 and is connected to node 2, it needs to be an attribute)
need...

1

votes

1

answer

5.6k

Views

### R shiny reactive data subset

With the help of fantastic people here at Stackoverflow I've managed to build a shiny web app (thanks to shiny server developers) that lets me select the dataset to use and plots a nice table showing the complete dataset. Now I want the user to input a date range then to show the table for the data...

1

votes

2

answer

5.8k

Views

### Can't connect to AWS Redshift using RPostgreSQL

I'm not able to connect to my AWS Redshift database using RPostgreSQL.
Does anyone have an example of code that would work?
library (RPostgreSQL)
drv

1

votes

2

answer

841

Views

### Factorize a numeric variable with Greek expression in labels in R

Suppose the following data frame, I want to factorized var, and label numbers to Greek letters, from 1 to alpha, 2 to beta, 3 to gamma. But the following code does not work.
var

1

votes

3

answer

660

Views

### replacing values from two columns in R

I have a data frame that is 24 columns and the second and third column look like
1 2230
1 2300
1 2330
1 2400
2 30
2 100
This is just a part of the columns. Column two has 48 ones then 48 twos then 48 threes and so on all the way to 365. column three is the half hour time and starts with 30 t...

1

votes

2

answer

1.4k

Views

### Exporting Arabic Text from R

I'm trying to export a data frame with Arabic text in R.
When R imports Arabic text it converts it to UTF-8 codes. Like this:
.
Unfortunately, I can't get it to turn back into readable Arabic when exporting. Below is code I'm using...
write.csv(my.data,"data.csv", fileEncoding='UTF-8')
Anybody h...

1

votes

1

answer

639

Views

### R function pmvnorm: Why do values and errors differ every time I run this function with the same inputs?

In my understanding, pmvnorm in mvtnorm library is a function to compute the CDF over a multivariate normal distribution. So it is a deterministic function. However, I found that the results change every time I run this function with the same inputs. Here is a small example.
library(mvtnorm)
lower

1

votes

1

answer

591

Views

### R shiny: ERROR: argument “metaHandler” is missing, with no default

I have a shiny app that runs fine on Windows (localhost), but when I upload it to a server, it returns the error:
ERROR: argument "metaHandler" is missing, with no default
I know that the server is fine, because all the other apps in the directory are working correctly.
I have seen Joe Cheng's res...

1

votes

1

answer

456

Views

1

votes

1

answer

1.3k

Views

### Using factor with levels gives me NA

there's something I cannot figure out
here is my data set
Proband Lauf Interleukin Ansatz Zeitpunkt
1 3 2 IFNy stim ZP21
2 3 2 iL2 stim ZP4
3 3 2 iL2 stim ZP14
4 5 3 iL2 stim ZP...

0

votes

2

answer

23

Views

### Creating Time Series columns in R from Long to Wide format considering Date Range

To start with I've successfully converted my data from long to wide format.
The data is as below.
+======+==========+======+======+
| Name | Date | Val1 | Val2 |
+======+==========+======+======+
| A | 1/1/2018 | 1 | 2 |
+------+----------+------+------+
| B | 1/1/2018 | 2 | 3...

0

votes

0

answer

23

Views

### Multiple regression of variables with different units

I'm new in statistical modelling and using R, so please excuse my mistake for this question.
I want to make multiple regression model with these variables:
Revenue (in million USD) as dependent variable
Customer experience score (with scale 1 to 5) as independent variable
Number of package return (i...

1

votes

1

answer

2k

Views

### R ggplot2 draw line from point to y=0

I have a data frame with 3 columns. I am plotting a factor (X) by a numeric variable (Prob). I would like to draw a line from each point down to the y=0 line. I tried to do this with the code below after reading this post R ggplot vertical and horizontal line intercept at center. The results were no...

1

votes

1

answer

8.8k

Views

### Customize range heatmap.2

I am using the heatmap.2 function from the "gplots" package and would like to tweak the vizual output.
I would like to get a symmetric color scheme and I have achieved that using the scale="row" option. However, when doing this, my range gets narrowed down to a small interval c(-1 , 1). The range of...

1

votes

1

answer

404

Views

### Unexpected row(s) of NAs when selecting subset of dataframe

When selecting a subset of data from a dataframe, I get row(s) entirely made up of NA values that were not present in the original dataframe. For example:
example.df[example.df$census_tract == 27702, ]
returns:
census_tract number_households_est
NA NA NA
23611...

1

votes

1

answer

872

Views

### Calculate number of consecutive day with the same condition in data [duplicate]

This question already has an answer here:
How can I count runs in a sequence?
2 answers
I have a data of temperatutre and I want to get the number of 4 consecutives days with this condition (Temp > Tmax) for each year I have.
For an illustrative example consider the following data frame of 5 colum...

1

votes

2

answer

10.3k

Views

### error message in r: no rows to aggregate [closed]

I am running a program written in r language which is designed to compile many csv data files into one csv file and then generate an output file that contains the output of simple calculations on the few variables selected in the combined file. The later process is done by using the combined file as...

1

votes

2

answer

844

Views

### How to format Gmisc::htmlTable

Below is an rmarkdown document that can be pasted into rstudio.
My problem is that output from htmlTable is prepended/appended with cruft from the htmlTable attributes.
---
title: "SO_question"
author: "AC"
date: "Wednesday, May 28, 2014"
output:
html_document:
theme: readable
---
My heading
======...

1

votes

1

answer

284

Views

### reorder data in ggplot

New and stuck in and at ggplot:
I have the following data:
tribe rho preference_watermass
1 Luna2 -1.000 hypolimnic
2 OP10I-A1 -1.000 epilimnic
3 B0_FO56C -0.986 hypolimnic
4 Planctomycetes_FGIDN -0.943 hypolimnic
5 acIV_IVNEG -0.943 hypolimnic
6 FTD4J6C01EE04F -0.941...

1

votes

2

answer

1.2k

Views

### converting time in factor format into timestamp

I've downloaded tweets in json format, converted it into csv, and read it into R. The existing time stamps are in factor format as shown below. How should I convert it into a timestamp that can be plotted against?
[1] Fri May 09 07:55:12 +0000 2014 Fri May 09 07:55:12 +0000 2014 Fri May 09 07:55:1...

1

votes

2

answer

199

Views

### Access Windows Registry inside R

How can I access the windows registry inside R. For example, I want to access the folder:
[HKEY_LOCAL_MACHINE\SOFTWARE\R-core\R\3.0.2]
and the key called "InstallPath"
to get:
"C:\\Program Files\\R\\R-3.0.2"
Many thanks!

1

votes

1

answer

875

Views

### R shiny app with rCharts

I'm able to create this graph with rCharts:
library(rCharts)
X

1

votes

2

answer

535

Views

### How to remove the emphasis characters on row names when using pandoc in R

I am using pandoc.table() to print out the data frame object, with certain cells highlighted by specifying the parameter, emphasize.strong.cells. But, the same emphasis characters on row names add some visual complexity. How can I remove these emphasis character on row names.

1

votes

2

answer

659

Views

### if subset yields zero observations skip to next value in r loop

I'm plotting data and I have a loop that first finds all data corresponding to a particular ID number. Sometimes there is no data for that particular ID so I need to add a if else if statement within the loop because other wise I get an error that there is no x values for the plot
Actual Code
df

1

votes

1

answer

1.4k

Views

### Solution of system of inequalities in R

I have the following system of inequalities: Ay >= 0, where A is a 9x3 matrix, and y = (y1, y2, y3) is a vector of 3 elements. The solution of the inequality is a region, but I would like to return one possible tuple (y1, y2, y3) that would solve this inequality. Note that all elements of y have to...