Newest r Questions

Q&A for professional and enthusiast programmers

Convert numeric values of a data table to dates

I want to convert a data table containing numeric values for 305 variables and 361 observations into a data table of same size containing dates. The data table does contain "NA"s. The numeric value ...

Read in a .txt file and delete line elenents

I have a .txt file that contains values and is tab seperated. It looks like this: G-clef E1,E1,B0,G0 E1 E1 E1 E1 F1,C#1,A0 G1 A1 G1,C#1 G1,D1,C#1 C#2 B1,F1 C#2 C#2,G1,E1 C#1 C#1 C#...

Shading only few counties in a chloropeth map using FIPS codes in R

I am new to R as a whole, I know that some of the packages in can help me render maps at county level, What I need is apply color /shades to some counties, for example in Texas, not all of them, So I ...

Add column across rows condtionally

with df like below df <- data.frame( name = rep(c("A", "B", "C"),2), type = c("10", "10", "10","20", "20", "20"), val = c(1,2,3,4,5,6) ) > df name type val 1 A 10 1 2 B 10 ...

How can I plot a component model of an averaged model (MuMIn)?

I have created a model-average and would now like to plot the linear relationship between the response variable and the sole significant predictor (component model) using the model-averaged ...

Bar chart overlay in Plotly R

I would like to overlay 2 bar charts in Plotly (R), but cannot figure it out. Can easily be done in ggplot2, but qqplotly renders it incorrectly so I would like to make the chart in plot_ly. Thanks ...

R: aggregate with custom function and external parameter

I have data like this: club <- c("a", "b", "c", "d","d", "a") all.scores.math <- c(1,2,5,3,4,4) all.scores.english <- c(2,2,4,3,4,1) data <- cbind(club, all.scores.math, all.scores....

How to plot test data into svm.plot of R package e1071?

I have built a SVM model using the R package e1071 and the iris data set. I have split up the iris data into a training and test data and built the SVM from the training data. Now I would like to plot ...

R scraper returning null

I'm trying to scrape the locations off some rental property listings website using R (rvest). The website has locations in the form as a embedded google map with a pin on the general location of the ...

Dummy variables interaction

I have a model like this EG= α0 + ∑βi*X + ∑ϕi DPEG *X + ∑ϒi DPayout *X + ε where DPEG and DPay are dummy variables, X is the vector of independent variables (Payout,etc) β1, φ1, ϒ1 are the ...

How to Make Interactive Map in R

I am interested in making an interactive plot in R+Shiny (or R and some other package) that is similar in spirit to this one: http://benschmidt.org/migration2/. I don't need to have two plots side-by-...

Unable to send an email from mailR package

For a day, I have been trying to send an email to my gmail account but unfortunately nothing is working. I have tried with different ports on the smtp.gmail.com and also enable google setting for less ...

Any alternatives of solve() which is slow

A represents how much each industry of country is related to other industry of other country. It could takes values from around 1.00. So diagonal element of matrix A is close to 1 but the off diagonal ...

Undefined Columns Selected in RDA from klaR

For the life of me I cannot work out why I cant get this code to work: rda(taste ~ . -quality, data = train) I keep getting the error "Error in [.data.frame(m, xvars) : undefined columns selected" ...

Not getting the expected plot from facet_grid in ggplot

I'm unsure why facet_grid is generating different charts than I get without using facet_grid. If you have any ideas on why I'm getting two different results please let me know. Thank you :) my code: ...

How to use substring function with apply in R?

The dataset contains information about superheroes. This code removes the annoying bracket part from the string 'name': # package loading library(fivethirtyeight) # data opening data(package ="...

start at the second element in a for loop in R

I have a issue with a for loop which should apply an ANOVA in a dataframe for(i in nom_soilbis){ anova_s[1,i]=aov(mt_s[,i]~mt_s$temps)$p.value } Error message is "number of items to replace is not a ...

Adding quarter average column

I have a data frame containing 20 year monthly house prices (columns) for 100 cities (100 x 20 matrix). I need to calculate the quarterly averages city_homes_subs$Q12016 <- ((city_homes_subs$`...

How to give multiple conditions in geom_Text

I have the following plot of a stock's price in response to time on different days. Currently, using geom_text I'm able to label the points of interest where the Y value deviates from 0 by a ...

Error when extracting tweets from twitter using r

I have started using R. I keep getting this error Error in tw_from_response(out, ...) : unused argument (until = "2016-11-28") when trying to run code PBunting<- userTimeline('@PeterBuntingMP',n=...

Rpy2 and Django Error: C stack usage 69077360 is too close to the limit

I am creating a django project in Windows in which I need to call few existing R codes (saved as .R files) via django views functions. To achieve this, I am using rpy2 python library. After including ...

Why 1^NA is 1 but 1*NA is NA

This is very basic question. 1^NA gives 1, but 1*NA gives NA. Any other numeric such as 1.1 or 2 to the power of NA gives NA Is there a way to set an option which would give 1^NA as NA?

How to determine which columns/values in a dataset/dataframe can be Predicted which cannot?

I have a data-set/data-frame with columns Description, Department Name, Priority, Doctor name & Location.Description data comes as free text from from the UI. Based on historical description's ...

Plotting with aesthetic greater than 1

I try to make a plot using ggplot2 using this code: points <- data.frame(x = fit$points[, 1], y = fit$points[, 2]) ggplot(points, aes(x = x, y = y)) + geom_point(data = points, aes(x = x, y = y,...

ggplot2 doesn't know how to deal with data of class reactive

It seems that reactive encapsulated variables, so the variable inside tweets can not be accessed... so how to fix it ? or do not use reactive ? the csv file tweets_davin and just use both for 2 ...

fread() deals with quoted zero-prefixed colum different from read.csv()

I have a csv file with quoted numeric column such as "'0001',a\n'0002',b\n'0003',c", for fread(), the first column will be character but for read.csv() the 1st column will be numeric type. How can I ...

R: Non-conformable arguments, error when optimise a custom function

I wrote following function costFunc=function(par,dat){ state=sapply(mySamp,stateofMC,windDat=windDat) sum=0 for(i in 1:3){ state_loc=which(state==i) state_dat=dat[...

Fastest implementation to iteratively copy the previous row and then randomly overwrite one cell

This code is slow for n.col=31; n.row=1600000, and I can't think of how to optimize it in R. I need to know the balance of several items at each step, but only one balance changes per step. I have a ...

expand grid in python [duplicate]

I'm trying to run a code in python that creates all possible combinations of different variables value. in R the code will look like that: a=unique(df$a) b=unique(df$b) c=unique(df$c) d=unique(df$d)...

How to check the quality of a data file for data mining or further use? [on hold]

can someone tell me how to evaluate the quality of a data file ..?? What procedure is widely used to check the data Accuracy, Completeness, Consistency, Timeliness, Uniqueness, Validity and others ...

How to create a new column, by variables and match two data.frames?

My data includes data on different people (ID) over each Day of the week and the time they spend in different areas of the hospital or Ward. I am given this time, in minutes:seconds or Duration. An ...

R type III SS producing inconsistent results

I've been using type III SS in R for years now seemingly without issue. But now I'm having an issue with type III sums of squares in R producing highly inconsistent results with the car package. Yes,...

Convert a numeric value to a time in R

I have been given a file with time, in minutes.seconds, in the following format: TimeInput <- c(13.66, 14.08, 12.86) How do I convert a numeric value, for example 13.66, to minutes:seconds format ...

Plotting in R, not plotting

I'm trying to replicate the Visualization of a Randomly Generated Branching Process and the book does not have the plot command. I tried the following code but it's not plotting but also not giving ...

How to match similar documents in R

I have created two corpuses: one containing tweet texts and another containing company names. What I'm trying to do is find which companies are mentioned in tweets. Example document of a tweet: > ...

R Does knncat normalise data?

I am performing a knn analysis of some data. I have both categorical (with more than 2 factors) and continuous data. I found a package that accounts for this situation (knncat) but there's very little ...

How to calculate differences in timestamp by category using R?

I have data frame with 617k variables and I would like to calculate the time differences (in minutes) between any two rows for the same category (the category is IP). So far, I didn't find a relevant ...

How do I add tier constraints in pcalg as prior knowledge?

I know that I can add edge constraints as prior knowledge when I use PC algorithm in pcalg (fixedGaps and fixedEdges). In tetrad one can also add tier constraints as prior knowledge before using the ...

Is there a version of the pairwise.t.test function that handles weighted data?

I have the following type of data (it's a subset just for the example): mydf <- data.frame(Score = c(55.17241, 79.31034, 96.55172, 31.03448), Subgroup = c("A", "B", "C", "A"), ...

want to automate R and Photoshop connecting them with a click?

To run a program in R .Do some modifications on the graph with Photoshop and upload it on net through python. Is this possible?

Flatten List Keep Null Elements R [duplicate]

I need to flatten a list but keep the null elements. unlist() will remove the NULL or character(0) elements, which results in a vector with fewer elements than a list. How can I flatten a list ...

R set.seed does not produce consistent results

I am using a main R function to call a series of R functions from different scripts. In order to reproduce results, I set.seed in the beginning of my main script. In the code, sample() function to ...

How can I lemmatize english words (exapmle: 'run' and 'ran') using R to bring them all to the same tense?

I want to lemmatize english words such that all of them get converted to the same tense. For example, c("ran","run","running") should become c("run","run","run"). I have already explored R packages ...

Get the longest item from each element of the list

I have a list: a = c("aaaa", "bbbbbbb") b = c("a1", "b2", "c33") c = "d" d = list(a, b, c) How can I get the longest items from each element of the list without a loop? In other words the goal ...

How do I merge two time series to result in an object with only the dates from the smaller one (R)?

I have two daily time series ranging from 1st of Jan 2016 to 1st of Aug 2016, however one my my series only includes data from business days (i.e weekends and bank holidays omitted), the other has ...

How to create concentric ellipses in R plot

I was wondering how I can draw parallel concentric ellipses (oval shape lines) just like the grey, oval dashed lines in the picture below in my R plot? Here is my small R code: plot(1, ty='n', ann = ...

Switch between pages of Quartz plot window in R.app

I'm asking this question solely so that I can publicly document for others an answer that I found by experimenting after I was unable to find a similar question. (It's a simple answer, though not ...

Add Data Labels On Top of Bar in a Barplot in R [duplicate]

I would simply like to add the data values on top of every bar of the charts. How can I best do this? library("RColorBrewer") HOLD <- matrix(c(0.80, 0.70, 0.70, 0.65, 0.56, 0.56, 0.78, 0.54, 0.40,...

YTD/MTD/WTD % change in R

I have daily AUMs for 2 companies over 5 years. Each day I add a new row with yesterday's AUMs. Data looks something like this: Date FirmA FirmB 01/01/2001 100 ...

Remove terms in a DocumentTermMatrix that appear in ALL documents

I am using DocumentTermMatrix as follows: dtm = DocumentTermMatrix(corpus, control = list( #weighting = weightTfIdf, ...
Translating... 0%