Importing data into R (rdata) from Github
I want to put some R code plus the associated data file (RData) on Github. So far, everything works okay. But when people clone the repository, I want them to be able to run the code immediately. At...
View Articlehow can I write this nesting code probably?
Social_class <- ifelse(test = so_cla==("Lw"), yes = sample(x = c("LwL","LwR"), size = 2, prob = c(0.64,0.36)), ifelse(test = so_cla==("Uw"), yes = sample(x = c("UwL","UwR"), size = 2, prob =...
View ArticleError in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 0...
I've got a really annoying problem that I tried to solve multiple days but I wasn't able. The code that I want to run is the following:subsample2 <- as.data.frame(subsample) m.extremistvote <-...
View ArticleFor each ID, separate groups into columns and collapse multiple value strings...
I have a dataframe that looks like this:in.dat <- data.frame(ID = c("A1", "A1", "A1", "A1", "B1", "B1", "B1", "B1"), DB = rep(c("bio", "bio", "func", "loc"), 2), val = c("IPR1", "IPR2", "s43",...
View ArticleMap trough a nested list using regex to remove entrys of a character vector
I have a nested list (https://www.filehosting.org/file/details/841630/bribe.RData) which I want to transform into a tibble. In the list are some character vectors which differ in length from the other...
View ArticleRender Xaringan Rmd when using _site.yml file
I have a website set up with three files._site.ymlname: Website navbar: title: Website right: - text: Home - text: Info output: html_document: theme: flatly highlight: tango index.Rmd--- title: Welcome...
View ArticleHow to scrape a string from webpage in R using rvest
I have a vector with 602 URLs that starts like this:links <- c("URL1.com", "URL2.com", "URL3.com) Each URL links to a webpage.Somewhere on each of the webpages is a year in the format YYYY as in...
View ArticleR: Add interpolated values in between columns of dataframe?
I have a data frame that looks like thisRegion 2000 2001 2002 2003 2004 2005 Australia 15.6 18.4 19.2 20.2 39.1 50.2 Norway 19.05 20.2 15.3 10 10.1 5.6 and basically I need a quick way to add extra...
View ArticleRandom sampling with normal distribution from existing data in R
I have a large dataset of individuals who have rated some items (x1:x10). For each individual. the ratings have been combined into a total score (ranging 0-5). Now, I would like to draw two subsamples...
View ArticleCompare cluster composition over consecutive time points in R
Currently I am attempting to analyse neighbourhood relationships of objects, moving over time in a 2D coordinate system. Precisely I would like to cluster the objects dependent on their proximity to...
View ArticleImputing the missing observations with series mean for panel data in R
I have a panel data that contains some missing values for a number of variables. I want to impute the missing data with series mean for panel data. I tried to use the following code, but I do not know...
View Articlefind JSON in string with recursion limit in r (windows)
I want to build a function that extracts jsons from strings in a generic way (for variable string Formats) with R on Windows.Thanks to #SO I am using:allJSONS <- gregexpr( pattern =...
View ArticlePlot of igraph: how to highlight a set of vertices
I am working with the igraph package in R to highlight a set of vertices. E.g. inlibrary(igraph) actors <- data.frame(name=c("Alice", "Bob", "Cecil", "David", "Esmeralda")) relations <-...
View Articlecalculating number of days between 2 columns of dates in data frame
I have a data frame which has two columns of dates in the format yyyy/mm/dd. I am trying to calculate the number of days between these two dates for each observation within the data frame (and create a...
View Articlerenaming column names with dplyr using tidyselect functions
I am trying to rename a few columns using dplyr::rename and tidyselect helpers to do so using some patterns. How can I get this to work?library(tidyverse) # tidy output from broom (using development...
View ArticleIF ELSE function in R studio
Can somebody explain why this code results in 1 for input: exam(5)?exam<-function(x){ y<-1 if(x==1){ return(1) } else{ return(y*exam(x-1)) y<-y+1 } }
View ArticleShinyApps.io disconnected when shared file on server is updated
I have an app which runs with a permanent .xlsx file loaded to the server. This file serves the purpose of storing various data points in the app for each user, each time the app is run. In other word,...
View ArticleAdding a line through means using ggplot
I'm drawing a plot using the means grouping the data with two factors. As you can see I'm getting a vertical line but I want a line containing the points (One for each subplot). How can I do...
View ArticleHow do you combine Lapply() and dbListFields() to get all column names for...
I would like to create a short Catalog for myself out of a database which would show what tables and fields are available there with the combination of SAPPLY(), LAPPLY() etc. and DBListNames.So far I...
View ArticleAdd secondary axis with cumulative distribution to ggplot R
I would like to add the cumulative distribution to one of my ggplots. Somehow, I fail to get the scaling right. This is the sample:require(ggplot2) set.seed(123456) 'dummy df'...
View Article