formula

How can I replace one term in an R formula with two?

房东的猫 提交于 2019-12-09 16:43:28
问题 I have something along the lines of y ~ x + z And I would like to transform it to y ~ x_part1 + x_part2 + z More generally, I would like to have a function that takes a formula and returns that formula with all terms that match "^x$" replaced by "x_part1" and "x_part2". Here's my current solution, but it just feels so kludgey... my.formula <- fruit ~ apple + banana var.to.replace <- 'apple' my.terms <- labels(terms(my.formula)) new.terms <- paste0('(', paste0(var.to.replace, c('_part1', '

Library to Parse a string as a formula, that works with Windows Phone 7

怎甘沉沦 提交于 2019-12-09 15:35:31
问题 Are there any .NET libraries out there that will parse a string as a formula? ie; "if the user inputs "(2 +5) * 2", the library will be able to work out the calculation? Edit:Preferably something that will work with Windows Phone 7 without too much fiddling would be nice! 回答1: I posted source code for one that supports expressions, variables and functions. You can see it at http://www.blackbeltcoder.com/Articles/algorithms/a-c-expression-evaluator. 回答2: NCalc is a fairly nice library that

extract variables in formula from a data frame

泄露秘密 提交于 2019-12-09 14:40:28
问题 I have a formula that contains some terms and a data frame (the output of an earlier model.frame() call) that contains all of those terms and some more. I want the subset of the model frame that contains only the variables that appear in the formula. ff <- log(Reaction) ~ log(1+Days) + x + y fr <- data.frame(`log(Reaction)`=1:4, `log(1+Days)`=1:4, x=1:4, y=1:4, z=1:4, check.names=FALSE) The desired result is fr minus the z column ( fr[,1:4] is cheating -- I need a programmatic solution ...)

Update a cell's value according to colored cells - Google Docs Spreadsheet

女生的网名这么多〃 提交于 2019-12-09 14:03:36
问题 In Google Docs spreadsheet, I have some cells green and red colored. I want a cell having the count of those green/red colored cells. Can I have a formula to do this thing or any custome code for this? 回答1: This Google Apps Script should get you started (see example spreadsheet): function countRedBackgrounds() { var COUNT_RED = 0; var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Cell colors"); var dataRange = sheet.getDataRange(); for (var i = 1; i<dataRange.getNumRows(); i++

Maximum subset which has no sum of two divisible by K

折月煮酒 提交于 2019-12-09 09:16:39
问题 I am given the set {1, 2, 3, ... ,N}. I have to find the maximum size of a subset of the given set so that the sum of any 2 numbers from the subset is not divisible by a given number K. N and K can be up to 2*10^9 so i need a very fast algorithm. I only came up with an algorithm of complexity O(K), which is slow. 回答1: first calculate all of the set elements mod k.and solve simple problem: find the maximum size of a subset of the given set so that the sum of any 2 numbers from the subset is

Installing OpenCV with Brew never finishes

我的梦境 提交于 2019-12-09 05:39:47
问题 So I'm trying to install opencv using Homebrew but it isn't working. I used brew tap homebrew/science and then brew install opencv What happens is: ==> Installing opencv from homebrew/homebrew-science ==> Installing dependencies for homebrew/science/opencv: gcc, eigen, jpeg, libpng, libtiff, ilmbase, openexr, homebrew/python/numpy ==> Installing homebrew/science/opencv dependency: gcc ==> Downloading http://ftpmirror.gnu.org/gcc/gcc-5.1.0/gcc-5.1.0.tar.bz2 Already downloaded: /Library/Caches

Openpyxl Formula filling unique row values for entire column

早过忘川 提交于 2019-12-08 13:59:30
I'm trying to write a formula into a cell and write for the entire column. However, for each cell in the column, it reads =(E2-F2)/C2 . For each cell on the same column how do I get it so reads (E3-F3)/C3 and so on? import openpyxl wb = openpyxl.load_workbook('yes.xlsx') Sheet = wb.get_sheet_by_name('Sheet1') n = '=(E2-F2)/C2' for cellObj in list(Sheet.columns)[6]: cellObj.value = n wb.save("row_creation_loop.xlsx") From my comment, here is the for -loop code in full: # n = '=(E2-F2)/C2' # move this assignment into the for-loop for row, cellObj in enumerate(list(Sheet.columns)[6]): print

crystal reports split string formula

谁说我不能喝 提交于 2019-12-08 11:42:09
问题 I'm trying to only show the date portion of a string field. This is the format of the string: STARTED:/ 03/23/1983 TIME:/ 03:12 I need to remove "STARTED:/" and "TIME:/ 03:12" and only show the date portion of the string: 03/23/1983 . What formula can I use to do that? Thanks 回答1: The Crystal Reports help file is your friend and should be your first stop for simple questions on built-in functions and data types. In CR strings are just stored as character arrays so you can access them like

Calculating formulae in Excel with Python

陌路散爱 提交于 2019-12-08 08:58:27
I would like to insert a calculation in Excel using Python. Generally it can be done by inserting a formula string into the relevant cell. However, if i need to calculate a formula multiple times for the whole column the formula must be updated for each individual cell. For example, if i need to calculate the sum of two cells, then for cell C(k) the computation would be A(k)+B(k). In excel it is possible to calculate C1=A1+B1 and then automatically expand the calculation by dragging the mouse from C1 downwards. My question is: Is it possible to the same thing with Python, i.e. to define a

Openpyxl Formula filling unique row values for entire column

南楼画角 提交于 2019-12-08 08:09:52
问题 I'm trying to write a formula into a cell and write for the entire column. However, for each cell in the column, it reads =(E2-F2)/C2 . For each cell on the same column how do I get it so reads (E3-F3)/C3 and so on? import openpyxl wb = openpyxl.load_workbook('yes.xlsx') Sheet = wb.get_sheet_by_name('Sheet1') n = '=(E2-F2)/C2' for cellObj in list(Sheet.columns)[6]: cellObj.value = n wb.save("row_creation_loop.xlsx") 回答1: From my comment, here is the for -loop code in full: # n = '=(E2-F2)/C2'