formula

In R formulas, why do I have to use the I() function on power terms, like y ~ I(x^3)

一曲冷凌霜 提交于 2019-11-27 11:07:05
I'm trying to get my head around the use of the tilde operator, and associated functions. My 1st question is why does I() need to be used to specify arithmetic operators? For example, these 2 plots generate different results (the former having a straight line, and the latter the expected curve) x <- c(1:100) y <- seq(0.1,10,0.1) plot(y~x^3) plot(y~I(x^3)) further, both of the following plots also generate the expected result plot(x^3, y) plot(I(x^3), y) My second question is, perhaps the examples I've been using are too simple, but I don't understand where ~ should actually be used. The issue

Convert light frequency to RGB?

ε祈祈猫儿з 提交于 2019-11-27 10:09:58
Does anyone know of any formula for converting a light frequency to an RGB value? Here's a detailed explanation of the entire conversion process: http://www.fourmilab.ch/documents/specrend/ . Source code included! For lazy guys (like me), here is an implementation in java of the code found in @user151323 's answer (that is, just a simple translation from pascal code found in Spectra Lab Report ): static private double Gamma = 0.80; static private double IntensityMax = 255; /** Taken from Earl F. Glynn's web page: * <a href="http://www.efg2.com/Lab/ScienceAndEngineering/Spectra.htm">Spectra Lab

Too many 'if' statements?

≯℡__Kan透↙ 提交于 2019-11-27 09:57:36
The following code does work how I need it to, but it's ugly, excessive or a number of other things. I've looked at formulas and attempted to write a few solutions, but I end up with a similar amount of statements. Is there a type of math formula that would benefit me in this instance or are 16 if statements acceptable? To explain the code, it's for a kind of simultaneous-turn-based game.. two players have four action buttons each and the results come from an array (0-3), but the variables 'one' & 'two' can be assigned anything if this helps. The result is, 0 = neither win, 1 = p1 wins, 2 = p2

Showing string in formula and not as variable in lm fit

久未见 提交于 2019-11-27 09:49:16
I am not able to resolve the issue that when lm(sformula) is executed, it does not show the string that is assigned to sformula . I have a feeling it is generic way R handles argument of a function and not specific to linear regression. Below is the illustration of the issue through examples. Example 1, has the undesired output lm(formula = sformula) . The example 2 is the output I would like i.e., lm(formula = "y~x") . x <- 1:10 y <- x * runif(10) sformula <- "y~x" ## Example: 1 lm(sformula) ## Call: ## lm(formula = sformula) ## Example: 2 lm("y~x") ## Call: ## lm(formula = "y~x") How about

VBA to open Excel hyperlink does not work when hyperlink generated with a formula

可紊 提交于 2019-11-27 09:34:11
There seems to be a bug with Excel hyperlinks which are generated with a formula. I'm using Excel 2010. I have a spreadsheet with cells containing URLs, and my goal is to do the following two things: Turn these cells into hyperlinks. Create a keyboard shortcut to open these hyperlinks so I don't have to use the mouse. To do #1, initially I just used the function =HYPERLINK() . So, my URLs are in column A , and I used this formula to make hyperlinks in column B . To do #2, I created the following macro which should open the hyperlink with the keyboard shortcut Ctrl + H : Sub Open_Hyperlink() '

Native SQL query for an Hibernate entity using @Formula results in NullPointerException

泪湿孤枕 提交于 2019-11-27 07:46:05
问题 I've got an simple Hibernate entity for which I use the @Formula annotion: @Id private Long id; private String name; @Formula("(select count(f.*) from foo f where f.id = id)") private long bar; When I try to load an entity with a native SQL Query: EM.createNativeQuery("SELECT f.*, count(something) as bar FROM foo f WHERE f.name = '...'", Entity.class) I get an NullPointerException: java.lang.NullPointerException at org.hibernate.loader.DefaultEntityAliases.intern(DefaultEntityAliases.java:193

Padding a fixed number with leading zeros up to a fixed length [closed]

核能气质少年 提交于 2019-11-27 07:35:07
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 7 years ago . In Crystal Report using Visual Studio 2010, I am trying a to create a formula for the following scenario: x = any number (Fixed number of 8 digits, cant be less or greater) If Length of X is less than 8, pad the

What does the capital letter “I” in R linear regression formula mean?

扶醉桌前 提交于 2019-11-27 07:28:23
I haven't been able to find an answer to this question, largely because googling anything with a standalone letter (like "I") causes issues. What does the "I" do in a model like this? data(rock) lm(area~I(peri - mean(peri)), data = rock) Considering that the following does NOT work: lm(area ~ (peri - mean(peri)), data = rock) and that this does work: rock$peri - mean(rock$peri) Any key words on how to research this myself would also be very helpful. I isolates or insulates the contents of I( ... ) from the gaze of R's formula parsing code. It allows the standard R operators to work as they

Mathematical expression (string) to number in Java

允我心安 提交于 2019-11-27 07:00:07
问题 I'm trying to find something like Java Embedding Plugin (JEP) that can evaluate a mathematical formula (string) and give back the answer. But it should also calculate a variable, for example: (25+36+x)*2 = 25 should give: x = -11 A little like http://www.wolframalpha.com/, but it shouldn't be that versatile, and it should work off-line. Open source is preferred. I need it for my little calculator project, http://sourceforge.net/projects/calex/. 回答1: This is called Arithmetic evaluation . One

Concatenate column headers if value in rows below is non-blank

半世苍凉 提交于 2019-11-27 05:31:00
I have table with data in the format below. Data I want the finished table to have the blank column to be populated like the highlighted one below. Finished Table So, I need a formula or VBA that will return and concatenate the headers of non-blank cells in each row. Use¹ the following as an array formula . =TEXTJOIN("-->", TRUE, IF(LEN(C3:I3), C$2:I$2, "")) Pre-Excel 2016 versions While you could just string together a series of IF statements, a cleaner alternate might be to write a user defined function (aka UDF). In a standard VBA module code sheet: Function udf_Stitch_Together(r As Range,