Newest r Questions

Q&A for professional and enthusiast programmers

How can I subset data with a conditional based on quantiles in dplyr? [duplicate]

I have data that looks like the following week<-rep(1:4,2) views <- c(45,53,13,45,78,55,32,34) article<-c("A","A","A","A","B","B","B","B") df<-data.frame(week,views,article) I want to ...

R ranking approach [duplicate]

I have the following code > x <- c("A", "B", "A", "C", "B", "A", "D") > df <- data.frame(x) > df x 1 A 2 B 3 A 4 C 5 B 6 A 7 D > I eventually want to mark the data frame rows ...

Filter_select and Crosstalk not functioning with reactive data

This may be related to a general issue posted here: https://github.com/rstudio/crosstalk/issues/34 I have a flexdashboard with shiny and want to use an input in crosstalk with filter_select. I am ...

Remove rows from R dataset based on matching

I did a word learning experiment with 54 participants. The design was such that each participant would be learning 12 cognate words and 12 non-cognate words. However, I had to remove some observations ...

Finding intersection points between a line and a triangle in R

I am trying to find the points of intersection of the paths and a triangle. Output can be the simple matrix having set of longitude or latitude points of paths which intersects a triangle. And these ...

plot.new has not been called yet when making tiff-file

I am trying to add text (the nonlinearity p-value) to a plot of a restricted cubic spline regression model. When I try this in R studio it works fine, however the moment I try to add code to save it ...

R: [unixODBC][Driver Manager]Can't open lib 'SQL Server' : file not found

setwd("/mnt/mountpoint/abc/") sqlServerConnString <- "SERVER=server;DATABASE=sqldwdb;UID=xyz;PWD=abc;" sqlServerDataDS <- RxSqlServerData(sqlQuery = "SELECT * FROM xyz", ...

How to run an Rmd shiny markdown doc from online repo?

I have an interactive knitr/rmarkdown doc that uses shiny apps. I want to place the .Rmd file on either my personal site or GitHub. How would I be able to remotely run this file directly from online? ...

Merge two ggplot as one [on hold]

I have two ggplot using 2 different dataset as below how can i merge them together. 1) ggplot(dt_aggregate, aes(x=hour, y=count, group=1)) + geom_point() + theme_bw() + geom_line(stat = "identity")...

R: na.action=na.exclude not working with mlogit

I am trying to add the fitted values of my multinomial logistic regression to the original data frame (called "ORDERS"). Unfortunately this is not possible, as apparently the predicted probabilities ...

Could not allocate memory R data frame to Oracle SQL table using rodbc

I want to insert a data frame from R into an existing table in my Oracle database using this code: sqlSave(connection, df, tablename = "oracle_table", append = TRUE) I get the error could not ...

Speeding up the performance of write.table of complex data

I have a big number of data.frames and I want to write them out (in different locations). For the moment I use write.table(), but it would take me around 2.5 days to output all of these. I have ...

improving neural network forecasting accuracy [on hold]

I am trying to forecast the daily electricity load using Neural Networks using regressors. Plotting the residuals, the mean is not very close to zero, autocorrelation could still be found and the ...

makeCluster cannot open the connection — error handling strategies?

An automated system is used to launch an R script that uses makeCluster to open a cluster of 35 nodes on a machine with 36 CPUs. (AWS c4.8xlarge running up to date Ubuntu and R) n.nodes = 35 cl <- ...

sequence of strings of letters in R

I have a data set (GRE) with about 40000 rows and 400 columns. I need to identify for each participant (Subject) and each trial (Trial) in column LABEL two sequences of strings: 1) pret1 followed by ...

Select/deselect entire group based if condition is met even once (dplyr)

Following the example from here I've tried to remove all groups containing even a single NA value in my data value frame exp_ID name nm_steps 1: 52797 1 A A1 NA 2: 49065 2 ...

How to get content or length of current console output?

I'm looking for the functions get_output_content or at least get_output_length below, that would tell me how many characters were printed in the console. test <- function(){ cat("ab") cat("\...

R Upgrade on Ubuntu 17.04(Zesty Zapus) issue

I am trying to update the R 3.3.0 to R 3.4.0 on my Ubuntu 17.04(Zesty Zapus) but I got the following messages : ** (gedit:10540): WARNING **: Set document metadata failed: Setting attribute ...

R: Time Efficient Way of Renaming Columns/Rows of a Matrix

Is there a more efficient way of doing this: The matrix expr is 15745 x 41 for (i in 1:ncol(expr)){ colnames(expr)[i] <- paste0("V",i); } for (i in 1:nrow(expr)){ rownames(expr)[i] <- ...

Merge (full join) recursively one data.table with each group of another data.table

I have 2 data.tables: a.id <- c("a","a","a","b","b","c","c","c","c") b.id <- c(1,2,3,4,5,1,3,4,5) x <- seq(1:9) dt1 <- data.table(a.id,b.id,x) and rp <- c("r","s") t <- rep(rp, ...

How to convert factor to date object in YearMonth format

I have factor data as follows in dateData: Factor w/ 24 levels "Apr 2017","Apr 2018",..: 11 3 23 21 19 5 9 7 15 1 ... I am converting factor data into Date object as follow: dateData1 <- as....

variable y dimension in geom_tile ggplot2

I would like to plot the values of this datatable: require(data.table) dt1 <- structure(list(Group = c(1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, ...

Please help me out with R code to join between two tables

Please help me out to create R script to join between two tables: Table A Table B I truly believe the merge should be done using filename, however, the PK's are different. What syntax should I use ...

Preparing a dataframe to use it in the mlogit package

What I did so far: I calculated a multinomial logit with the TravelMode dataset from the package AER. Everything went fine, so I went on and kicked all the options with mode == air plus the lines of ...

Extralarge XML to dataframe in R

I am new in R and I get stucked with extracting data large XML files. I have looked at some topics here, however not get there yet. I have xml which looks like this: <?xml version="1.0" ...

Installing packages from binary in R 3.4.0

I recently updated R to the latest release: 3.4.0. R is installed on a network location H:/. Now something weird is happening when I try to install a local binary package: filename <- paste0("R:/...

R, conditionally remove duplicated row - based on closest to a particular value

I have a dataframe in R containing the columns ID, Sex, Height and Age_Months. For each ID, there may be multiple entries of height at various ages (i.e. there may be multiple duplicate rows in ID e.g....

How to add multi-sub-columns in gridExtra::tableGrob

I'm attempting to engineer an R function that will accept a list and plot a table with specialized formatting. Here is my data: pottery <- list( `Llanederyn` = c( 14.4, 13.8, 14.6, 11.5, 13.8,...

check If program is running , if not , run it [on hold]

enter code here Error in file(file, "rt") : cannot open the connection Warning in file(file, "rt") : cannot open file 'C:\Users\deveyandu\Desktop\final phase\shiny\rankfb.csv': No such file ...

How to suppress expansion of x-axis and prevent the axis labels from being cropped? [duplicate]

See the follow plot for example: library(ggplot2) df <- head(mtcars, 4) df$rn <- rownames(df) #> mpg cyl disp hp drat wt qsec vs am gear carb #> Mazda RX4 21....

How to properly plot projected gridded data in ggplot2?

I've been using using ggplot2 to plot climatic gridded data for years. These are usually projected NetCDF files. Cells are square in model coordinates, but depending on which projection the model uses,...

Read first 10 lines csv file with rcpp [on hold]

I want to read with C++ the first ten lines from a big csv file with rcpp into R. Which package can i use? i wrote my Code in c++ and add to the Header "Rcpp.h" and Rcpp::Export. Thanks .

Subsetting based on two columns from two dataframes where the column names are different [duplicate]

I have two data frames, df1, chr start end 3676 chr1 793962 95298066 2913 chr20 13200929 13200929 and df2 chr pos strand fit cg15903280 ...

Calling R script from Java using rserve

I am doing a school project where i use logistic regression for a heart attack prediction. My application consists of Java GUI where i use dialog windows to get data from user and then i write them ...

How to use a combination of top-down and bottom-up approach on complex hierarchical time series using hts in R?

I am trying to evaluate the performance of hierarchical forecasting methods using different base forecasting levels of two hierarchies of different dimensions (product and location). Performance is ...

Sample random rows in dataframe with probability

How can I take a random sample (with or without replacement) but with given probabilities? I am trying to extract a random sample of rows in iris data frame but with this condition of species: 80% ...

Extracting numeric values from string in R, using regular expression [duplicate]

Using gsub (or similar), what regular expression do I need to write to extract the following information out of this string: Position: X= 522.1mm; Y= -316.3mm; Z= 358.3mm; A= 160.71°; B= -0....

Using X11-forwarding for Docker containers

I am trying to build a Dockerfile which contains an Rscript through Docker run. I am facing an error related to tcl/tk package loading while building it for which I want to use X-11 forwarding and ...

Error: incompatible types (from S4 to double) in subassignment type fix (R) (robustfa)

Being relatively new to R, I want to use the function FaCov from the robustfa package for my exploratory factor analysis. Unfortunately, I receive an error message for which I cannot find any solution ...

RStudio - How do I view a certain section of my dataset of people (for example, only females)?

I have a dataset called "data" and I have a column in it called "gender." I want to look at all the data where "gender" = F only. How would I go about doing this in the RStudio console with code?

Subtracting date from date in a different row and column using for loop in r [duplicate]

This question is not to find just the difference of dates. I have a data frame which has two date columns.Purchased_date and Due-date. Now I want to subtract (due-date) - (2nd purchase date). For ...

R, keras: TypeError: Value passed to parameter 'shape' has DataType float32 not in list of allowed values: int32, int64

I'm trying to make some neural networks in R, using kerasR package on tensorflow within a tensorflow anaconda environment. Here you can see my setup: library(reticulate) use_condaenv("tensorflow", ...

Making lmmodel with demographic and dummy variables

im completly new in R and also in economteric. Im working on my school project and i need to run model, which should explain the dependecne of property prices on their position in the city. The model ...

binding data in different order produces the same histogram

I have this data: hours <- 1:5 frequency <- c(41, 72, 48, 20, 21) I am binding them: result <- cbind(hours, frequency) result hours frequency [1,] 1 41 [2,] 2 ...

Meaning of ~. operator in R

Can someone explain me the below line of code. I am very new to R. I am finding it difficult to understand the below line of code xtabs(cbind(ncases, ncontrols) ~ ., data = esoph) Here xtabs ...

Converting text in to data.frame

I have several records of the following text data (this is a single record). I want to convert this text into a data.frame. I want to make column headings e.g. LOCUS, DEFINITION, ACCESSION and so on......

How to generate a list of certain subsets of x in r?

I want to generate a set in r which contains all of its subsets but not the set itself. For example, say I have the set {1, 2, 3} I want to generate the following list in r {{}, {1}, {2}...

Sql query including a unicode character returns wrong result

I have a query like this: select * from Table where column1='bäb' This query returns a result in SQL Server, but if I write it in RStudio: res <- sqlQuery(dbhandle, "select * from Table where ...

Predict whether the customer gross sales for the next month category for a product and Territory based on customer’s historical monthly sales data

I am new to R programming and I have to do some kinda POC(Proof of Concept) work at my workplace in which I have to predict the gross sales for the next months for customers based on product and ...

how to translalte option in redux framework with wpml or another plugins wordpress?

i have a site with two languages. i'm using w.p.m.l plugins to translate all thing. but, when i show the panel of this r.e.d.u.x framework I can't translate option in input ...
Translating... 0%