aggregate per variable over which sums are calculated in R data.table
I have some time datalibrary(data.table); library(lubridate); set.seed(42) dat <- data.table(time=as.POSIXct("2019-01-01 08:00:00") + round(runif(10,60,1e4)), val=runif(10))[order(time),...
View ArticleHow to iterate over multiple vectors
Fairly new to R. Been working on this for a while but can't seem to get it working. I am trying to create a column called peo$Tier. It has 3 levels, ("1", "2", "3")tier1 <- c("ADP TOTAL SOURCE INC",...
View ArticleCreate a vector that contains the first 10 powers of 2, then the first 10...
I try to use x <- rep(2,10) , but I don't know what I should do next. Can anyone give me some advice? Thanks in advance.
View ArticleUse python 3 in reticulate on shinyapps.io
I have some code in Python 3 which I'm running in R through the reticulate library to use in a shiny app. It works fine in my local machine, but when I published in shinyapps.io reticulate is using...
View Articlehow to extract specific digits in R (including NA)
I've extracted the specific value from dataframe successfully in R. However, there's another problem that I can't solve. If there's any help that would be appreciated.the raw data looks like as below:...
View ArticleIn ggplot2, how can I seperately plot four group of one csv file in barchart?
I am a beginner in R. I have one question.I am trying to make the multiple bar aFor doing this, I am using the below datagender party likes_count <chr> <chr> <dbl> 1 F D 587. 2 F R...
View ArticleHow to craft this function in R?
I am currently trying to write a function that estimates energy expenditure of some lizards through E = e21.44 * (e(8.74901^10−20 / (1.3806488*10−23 *T). T in the equation is equal to the temperature...
View ArticleCreate a variable name with "paste" in R?
See below:paste("perf.a", "1", sep="") # [1] "perf.a1"What if I want to assign a value to perf.a1?I tried as.name, as.symbol, etc., with no avail:as.name(paste("perf.a", "1", sep="")) = 5 # Error in...
View ArticleExport dataframe in Excel format
I would like to save a dataframe in Excel format, but the usual functions (WriteXLS, write.xls) are not working.WriteXLS::WriteXLS(test, "test.xls") The Perl script 'WriteXLS.pl' failed to run...
View ArticleGet world region name from a country name in R
In my data I have one column with country names. I want to make a new variable that lists which region each country is in based on an excel sheet I have where I have labelled each country by region. I...
View ArticleLooping a Function over Groups and Years
I have a sample of many countries across several years that contains information on output (GDP). I would like to calculate the "Output Gap" using a function I found at R-Bloggers here, but would like...
View Articlehow to save decision or classification tree plots?
Recently I am working on the classification and decision tree in R. I have two questions:(1) what is the difference among several terms such as "classification tree", "decision tree" and "regression...
View ArticleBlock bootstrap from subject list
I'm trying to efficiently implement a block bootstrap technique to get the distribution of regression coefficients. The main outline is as follows.I have a panel data set, and say firm and year are the...
View ArticleMerge r brings error "'by' must specify uniquely valid columns"
R doesn't like me today...I have two tables asembled via cbind(). Tab 1 (dwd_nogap) is x1 col1_x1 col2_x1 A "1982 12 01 00:00"" 0.4"" 0" B "1982 12 02 00:00"" -0.5"" 0" C "1982 12 03 00:00"" -0.2"" 0"...
View ArticleMatrix in R programming
learning R programming recently, here's a exercise I cannot figure it out. This program that asks the user for the 8 values of a 2 2x2 mathematical matrix. Another words, there are 4 values in one 2x2...
View ArticleTransforming R dataframe by applying function rowwise and create (possibly)...
I'm trying to transform a dataframe (tibble) by using each row as function arguments and create a new column out of it, which is possibly bigger than the number of arguments. Consider the following...
View Article(R-3.5.3 mlrMBO) Error in...
I had an issue when I use mlrMBO(1.1.2) in R-3.5.3 to optimize my function, anyone know why? many thanks!THE ERROR:Error in generateDesign(control$infill.opt.focussearch.points, ps.local, : REAL() can...
View ArticleMap value from cross sectional data to longitudinal data in R
I have cross sectional data and longitudinal data in a cohort:# create dummy cross sectional data cross_sec_df <- data.frame(ID = letters[1:10], severity = sample(c("mild", "severe"), 10, replace =...
View ArticleR: Getting whisker to loop over a list with unknown names
I'm trying to use Whisker for HTML-templating in R, but seem to run into problems that should be an easy task for the package. All I want to do is to use sections to loop over a list, with the only...
View ArticleEfficient version for searching for two strings in two columns in R
I have a (large) data frame which has a structure relatively similar to this:id1 id2 symbol1 symbol2 scoreA scoreB scoreC 4790 1120 ABC LLL 1 0 1 2300 4790 NNN ABC 0 0 1 1120 4790 LLL ABC 0 1 1 1120...
View Article