variables

How to generate binary variable according to the conditions of other variables?

十年热恋 提交于 2019-12-31 04:03:28
问题 Once again, I apologize for asking this type of question, but the R world is so large that sometime I feel lost, even if I have read some of the best book related with R. I have the following DB ID=rep((1:3),3) x<-as.Date("2013-1-1") y<-as.Date("2013-1-2") z<-as.Date("2013-1-3") DATE<-c(x,x,x,y,x,y,z,z,z) TRAP<-c(1,1,1,3,2,3,2,1,3) IN<-data.frame(ID,DATE,TRAP) and I would like to produce a binary variable (RESULT) according to the following conditions: if the DATE and the TRAP is the same for

Writing variables to new line of txt file in python

我的未来我决定 提交于 2019-12-31 04:01:11
问题 From other posts, I've learned that '\n' signifies a new line when adding to a txt file. I'm trying to do just this, but I can't figure out the right syntax when an attribute is right before the new line. My code I'm trying is like this: for item in list: with open("file.txt", "w") as att_file: att_file.write(variable\n) As you can probably see, I'm trying to add the variable for each item in the list to a new line in a txt file. What's the correct way to do this? 回答1: You just need to

PHP Session variables not being passed to the next page

纵然是瞬间 提交于 2019-12-31 03:44:08
问题 I know this title is duplicate to 1000's of other posts related to an issue and I apologize in advance if the solution is out there. Trust me I went through tons of posts regarding this topic and tried all the solutions prescribed, but have had no luck. I am trying to create SESSION variables through the following code in page 1: <?php $conditionArray = array('Past', 'Past', 'Future', 'Future'); $typeArray = array('Gains', 'Gains', 'Losses', 'Losses'); shuffle($conditionArray); shuffle(

Nested function definitions and scope (UnboundLocalError)

北慕城南 提交于 2019-12-31 03:35:06
问题 Why is the following code invalid: def foo1(x=5): def bar(): if x == 5: x = 6 print(x) bar() While this code is valid: def foo2(x=5): def bar(): if x == 5: print('ok') print(x) bar() foo2() will do exactly what you expect, but foo1() will give a UnboundLocalError: local variable 'x' referenced before assignment at the line if x == 5: . Why does altering the value of x later on in the code make this conditional invalid? 回答1: Python needs first to detect what variables are local , and which

Dynamic property name concatenation

微笑、不失礼 提交于 2019-12-31 03:28:05
问题 I'm looking for an easy way to assign to a variable depending on the value of another variable. device.slot2_clipList[clipNumber] = singleClipDetails; what I'm trying to do is: replace the "2" with another variable, so that i can run the same operation while just changing the var slotNumber, and write to the corresponding variable. i tried device.slot + device.slotNumber + _clipList[clipNumber] but (obviously?), this doesn't work. How can this be done? (Maybe I named the Question incorrectly,

How to use PHP variable in Javascript?

半腔热情 提交于 2019-12-31 02:55:10
问题 I know you can't directly use PHP variables inside javascript code, but is there a way around it? I need to use these parameter's in javascript: username: '<?php echo $user_id;?>.example.co.uk', password: 'example', Instead of showing the $user_id variable, it outputs: "Resource id #4.example.co.uk" I'm quite new to javascript so I'm finding it pretty tricky. Thanks for any help Edit: I am taking the $user_id variable from the URL like so: $user_id = mysql_real_escape_string($_GET["user_id"])

Should I store a calculation in a variable if it will be used a lot?

烈酒焚心 提交于 2019-12-31 02:53:07
问题 If I have a function to, for example, check if list1 is a sublist of list2 , which option is better: Option 1: def isSublist1(list1,list2): "This fuction checks if list1 is a sublist of list2." for i in range(len(list2)): part = list2[i:] # part is a list with all the elements from i to the end of list2 if len(part)<len(list1): return False if list1==part[:len(list1)]: # if list1 is in the beginning of part return True return False Or option 2: def isSublist2(list1,list2): "This fuction

PHP Undefined variable in functions and included scripts

久未见 提交于 2019-12-31 02:49:29
问题 I've read a LOT of things about this problem, however I still cannot fix it. In my functions file I declare a variable with a value like so: $px_host = "localhost"; And I have a database query function like so: function dbQuery($database, $reqquery){ if(!$connect = mysql_connect($px_host, $px_dbuser, $px_dbpass)){ exit("Error - cannot connect to MySQL server - " . mysql_error()); } if(!$database = mysql_select_db($database)){ exit("Error - cannot select database - " . mysql_error()); } if(!

Transferring int variable between activities Android

这一生的挚爱 提交于 2019-12-31 02:44:09
问题 I am making a quiz game. However, I need to add a score variable that can be modified. The way the game works is it uses a few different activities. How can I transmit this score and modify it throughout the activities. 回答1: Here's an example of passing an integer from one activity to another activity. Start ActivityA and pass it the int like this: Intent theIntent = new Intent(this, ActivityA.class); theIntent.putExtra("somename", intVariable); startActivity(theIntent); Get the integer from

PHP Templating

為{幸葍}努か 提交于 2019-12-31 02:44:07
问题 I'm writing a simple templating layer in PHP but I've got myself a little stuck. Here's how it works at the moment: Firstly I use fetch_template to load the template contents from the database - this works (and I collect all the templates at startup if you're interested). I use PHP variables in my template code and in the logic - e.g.: // PHP: $name = 'Ross'; // Tpl: <p>Hello, my name is $name.</p> I then use output_template (below) to parse through the variables in the template and replace