Categories
Mastering Development

Add legend in ggplot – point/line and segment

I want to add a legend to a ggplot. Unfortunately I can’t make the entries in the legend to belong to the same category. Either the entries are not on top of each other or the colors does not match. I would like to have it as shown on the attached picture. My code is: […]

Categories
Mastering Development

Split dataframe with all values in one row

I got the following dataframe which is created dynamically but saves all the relevant values into one row: df +—————-+—————-+—————-+—————-+ | 1 | 2 | 3 | 4 | +—————-+—————-+—————-+—————-+ | a1, b1, c1, d1 | a2, b2, c2, d2 | a3, b3, c3, d3 | a4, b4, c4, d4 | +—————-+—————-+—————-+—————-+ I need to […]

Categories
Mastering Development

minimization Converging to negative infinity despite constraints

I have the following optimization problem: from scipy import optimize import numpy as np def net_profit(x): return -(x[0] / (x[1] + x[2] + x[3]) * 365 * \ (x[4] – (x[5] + x[6])) * x[7] + \ x[8] * 12 – x[9] * 12) c0 = {‘type’: ‘ineq’, ‘fun’: lambda x: x[0]} c1 = {‘type’: […]

Categories
Mastering Development

Overlapping text on top of geom_bar in ggplot2

I have made a barplot similar to the one below using ggplot2. I cannot get the percentages on top of the bars to be centered and not overlapping of other bars and numbers. Sample code is below. library(tidyverse) cat1=c("cat1","cat1","cat1","cat1","cat1","cat1","cat1","cat1","cat1","cat1","cat1","cat1", "cat2","cat2","cat2","cat2","cat2","cat2","cat2","cat2","cat2","cat2","cat2","cat2", "cat3","cat3","cat3","cat3","cat3","cat3","cat3","cat3","cat3","cat3","cat3","cat3", "cat4","cat4","cat4","cat4","cat4","cat4","cat4","cat4","cat4","cat4","cat4","cat4") cat2=c("c1","c2","c3","c4","c5","c6","c7","c8","c9","c10","c11","c12", "c1","c2","c3","c4","c5","c6","c7","c8","c9","c10","c11","c12", "c1","c2","c3","c4","c5","c6","c7","c8","c9","c10","c11","c12", "c1","c2","c3","c4","c5","c6","c7","c8","c9","c10","c11","c12") count1=round(rnorm(48,10)) fakeperc=rnorm(48,9) df1=cbind(count1,fakeperc) df2=cbind(cat1,cat2) finaldf=as.data.frame(cbind(df1,df2)) finaldf$cat1=as.factor(finaldf$cat1) finaldf$fakeperc=as.numeric(finaldf$fakeperc) #finaldf$cat1=factor(finaldf$cat1,levels = […]

Categories
Mastering Development

How can I check if I have written a number or a letter in c++?

This is my first time on stackoverflow. I can not figure out how I can check if I have written a number or a letter. If i have written a letter I want the program to say that I neat to write a correct number. Everything is working except the part where the program asks […]

Categories
Mastering Development

Create an open ended question with learnr:tutorial in r

I want to allow students to input their student ID at the beginning of every quiz they take. There are no correct answers as long as they input a 7 digit number. This is what I have right now but the function does not run when the defined answers are sot one single text. How […]

Categories
Mastering Development

Setting up an arbitrage strategy in R by solving system of inequalities subject to an equality constraint

I am trying to construct an arbitrage portfolio x such that Sx = 0 and Ax>=0, where A is the payoff matrix at t=1 and S is the price at t=0. I was not able to do it manually, so I tried using functions contained in the limSolve and lpSolve packages in R with no […]

Categories
Mastering Development

how to put all the coef(model) parameters inside one dataframe in r

I got gathered coefficient outputs of several models like below, SWC_11 SWC_12 SWC_13 SWC_14 SWC_21 SWC_22 (Intercept) 1.047195e+04 4.063320e+03 7.504076e+04 7.742763e+03 2.296585e+04 2.185688e+04 day -6.563423e-06 -2.525118e-06 -4.726106e-05 -4.842427e-06 -1.443707e-05 -1.374111e-05 Now I want to put all the parameters inside one dataframe and named the columns with the same prefix as the above. My expected outputs […]

Categories
Linux Mastering Development

Split single column in multiple row and then format the data

I need some help I have data in below format in a single column: A:1 B:2 A:3 C:8 B:2 C:4 B:2 Need an output in below format: A,B,C 1,2, 3,2,8 ,2,4 Kindly suggest!!

Categories
Mastering Development

Function from script editor works fine but not from sheets -Google apps sctipt/calendar/sheets

I wrote a function that adds an all day event. When the function running from script editor it’s works fine, the all day event is insert to the calendar. But when I’m running the function in the active spreadsheet =addevent(a1,b1,c1,d1) I’m getting an error saying : Exception: The script does not have permission to perform […]