Quantcast
Browsing all 206073 articles
Browse latest View live

R match with previous observation

How can I match the latest available observation for HPG with the previous observation for HAR? I am looking for a general solution that would allow me to select the n-th previous observation. Below an...

View Article


Error when trying to make cluster using R (Rscript execution error: No such...

Hello and thank you for your time. I get the error: cl <- parallel::makeCluster(2) Rscript execution error: No such file or directorywhenever I try to make a cluster using the package "parallel"....

View Article


ggplot geom_bar not "stacked" or re-ordered

I am trying to do a few things to my plot. The code for the basic plot I have is the following:d %>% ggplot(aes(x = Major.sectors, y = reorder(Obs, Obs, function(x)-length(x)), fill = Status)) +...

View Article

Color points in overlayed scatterplots in ggplot R [duplicate]

Using this tibble as example:tibble( groups = c("a","b","c","d","e"), grade1 = c(510,405,308,201,99), grade2 = c(520,430,300,190,110), grade3 = c(530,410,320,210,105) ) How do I manage to color the...

View Article

Image may be NSFW.
Clik here to view.

How to overwrite values after grouping in R but preserving the initial value...

I would like to do a simple overwriting in R, but I guess is not as simple as I thought it would be. I have a beginning, an end, a majorCategory and a subCategory. For every majorCategory, there is a...

View Article


R: Why is this outer-call so slow? How can I speed it up?

Let a, b be two vectors of different length. I need to set up a matrix with elements exp(-1i*a*b), meaning for every pair of elements in a, b, I want to multiply by the imaginary unit, and then take...

View Article

Data Table R: molten or reshape data table without stacked variable column

Datastr(DT) Classes ‘data.table’ and 'data.frame': 6 obs. of 3b variables: $ A : Factor w/ 6 levels "0","1","2","3",..: 1 2 3 4 5 6 $ N : num 13 11 10 5 1 1 $ ID : Factor w/ 1 level "1": 1 1 1 1 1 1...

View Article

Is it possible to render a "runtime:shiny" rmarkdown (.rmd) file, using an...

Let's say we have this "runtime: shiny" RMD file I built on RStudio. It has 4 main parts: --- title: "Theory" output: html_document runtime: shiny --- Part 1: html code <style type="text/css">...

View Article


Changing multiple variables names following a specific pattern

I have a dataset with hundred of variables that looks roughly like thisdt <- data.frame(id= c(1,1,1,2,2,2,3,3,3), time=c(1,2,1,2,1,2,1,2,1), dp_eu_ = rnorm(9), EU_top = rnorm(9), fr_dp_us_ =...

View Article


Consecutive/Rolling sums in a vector in R

Suppose in R I have the following vector : [1 2 3 10 20 30] How do I perform an operation whereby at each index 3 consecutive elements are summed, resulting in the following vector : [6 15 33 60] where...

View Article

Image may be NSFW.
Clik here to view.

Add Additional Information In Tooltip R Highcharts

I have some data that I would like to graph using highcharts. When I hover over a given point, I would like the tooltip to also include the column "type". Here is my current reproducible...

View Article

How can I read a table in a loosely structured text file into a data frame in R?

Take a look at the "Estimated Global Trend daily values" file on this NOAA web page. It is a .txt file with something like 50 header lines (identified with leading #s) followed by several thousand...

View Article

use values from a column as index to extract a value from another column in R

Suppose I have this dataframe df: df <- data_frame(A = c(1:10), B = c(21:30), C = c(NA, NA, NA, 1, 8, 3, NA, 4, 7, 3)) A B C <int> <int> <dbl> 1 1 21 NA 2 2 22 NA 3 3 23 NA 4 4 24...

View Article


Remove rows from dataframe if they contain a certain value (R ,dplyr)

I have a dataframe, df. I would like to remove all rows that contain the value 0 from the dataframe. ID Value A 8 A 8 A 0 B 1 B 2 C 0 Desired outcome: ID Value A 8 A 8 B 1 B 2 Here is the dput:...

View Article

Rmakrdown not using most recent version of package functions to generate...

I'm using an Rmd to generate github markdown file. When I make changes to the package locally, build from source, then run knit -> knit to github document, the .md file generated still uses the...

View Article


Image may be NSFW.
Clik here to view.

Show element values in barplot

I'm trying to put original counts into a barplot, but it's always messy:set.seed(123) c<-c(2, 3.5, 5, 7.9, 8.8, 12.3) x<-sample(c, 100, replace=T) barplot(table(x)) text(c, table(x)+2,...

View Article

Image may be NSFW.
Clik here to view.

How can I annotate facets that do not have data using ggplot2 facet_grid?

I have multivariate longitudinal samples that I am plotting in a large facet_grid, specifically using facet_grid so that when I don't have a certain time point for a certain sample it still keeps...

View Article


Barplot of a column based on Values of another column

I have something like the following Dataset:1. Donation 2. Treatment 3. Category. 2€ TG2 Teenager 1€ TG1 Adult 2€ TG2 Adult and so on There are multiple participants. Every Participant is part of a...

View Article

Image may be NSFW.
Clik here to view.

Making a customized scale bar in a map

I have a map with a scale bar, which was made using the "scalebar" function in ggplot. But our journal editors require "Reformat the scale bar with tick marks at the numbers. Remove all distances of km...

View Article

Combining two dataframes, similar rows, similar columns except one colum has...

I have two dataframes that I want to combine into one. Rows in one dataframe are not always in the other and vice versa. I want to keep all rows and columns from both datasets. Additionally, there is...

View Article
Browsing all 206073 articles
Browse latest View live