shift

R data.table find lags between current row to previous row

南笙酒味 提交于 2019-12-11 02:45:21
问题 > tempDT <- data.table(colA = c("E","E","A","A","E","A","E") + , lags = c(NA,1,1,2,3,1,2)) > tempDT colA lags 1: E NA 2: E 1 3: A 1 4: A 2 5: E 3 6: A 1 7: E 2 I have column colA , and need to find lags between current row and the previous row whose colA == "E" . Note: if we could find the row reference for the previous row whose colA == "E" , then we could calculate the lags. However, I don't know how to achieve it. 回答1: 1) Define lastEpos which given i returns the position of the last E

Bash getopt - shift multiple parameters

ε祈祈猫儿з 提交于 2019-12-11 02:13:36
问题 I have a script to launch some checks on Ubuntu machine. I call my script like this : ./script -f /tmp/file.txt --modules 001 002 003 All files 001, 002, etc... are bash scripts. The following main function is my problem : main () { OPTS=`getopt -o hf:m: --long help,file:,modules: -n 'script.sh' -- "$@"` eval set -- "$OPTS" [ $# -eq 0 ] && echo "Unknown options or parameters" && USAGE while [ $# -gt 0 ]; do case "$1" in -f|--file) FILE="$2" shift ;; -h|--help) USAGE exit 1 ;; -m|--modules)

Pandas apply, but access previously calculated value

偶尔善良 提交于 2019-12-10 21:43:28
问题 Suppose I have a DataFrame (or Series) like this: Value 0 0.5 1 0.8 2 -0.2 3 None 4 None 5 None I wish to create a new Result column. The value of each result is determined by the previous Value, via an arbitrary function f . If the previous Value is not available (None or NaN), I wish to use instead the previous Result (and apply f to it, of course). Using the previous Value is easy, I just need to use shift . However, accessing the previous result doesn't seem to be that simple. For example

Check overlap begin and end time by group in R

丶灬走出姿态 提交于 2019-12-10 19:18:02
问题 I want to check overlap of data, here is data ID <- c(rep(1,3), rep(3, 5), rep(4,4),rep(5,5)) Begin <- c(0,2.5,3,7,8,7,25,25,10,15,17,20,1,NA,10,11,13) End <- c(1.5,3.5,6,12,8,11,29,35, 12,19,NA,28,5,20,30,20,25) df <- data.frame(ID, Begin, End) df ID Begin End 1 1 0.0 1.5 2 1 2.5 3.5 3 1 3.0 6.0* 4 3 7.0 12.0 5 3 8.0 8.0* 6 3 7.0 11.0* 7 3 25.0 29.0 8 3 25.0 35.0* 9 4 10.0 12.0 10 4 15.0 19.0 11 4 17.0 NA* 12 4 20.0 28.0 13 5 1.0 5.0 14 5 NA 20.0 15 5 10.0 30.0 16 5 11.0 20.0* 17 5 13.0 25.0

How do you determine if a character requires the shift key to be down to be typed?

佐手、 提交于 2019-12-10 18:48:24
问题 I am writing some code to type strings using the Robot class. Everything is mostly good (well, I have to use a big switch statement to get character keycodes), except some keys don't have keycodes, because they are actually a combination of Shift + some other key. For upper case letters, it is easy to check, using Character.isUpperCase(c) , but for all the symbols such as !@#$%^&*()_+ and various punctuation are not considered "upper case" although they do require shift to be pressed in order

Why is `int >> 32` not always zero? [duplicate]

纵然是瞬间 提交于 2019-12-10 18:42:44
问题 This question already has answers here : Weird behavior of right shift operator (1 >> 32) (7 answers) Closed 4 years ago . Can someone explain me why right 32 bitwise shift of some 4 byte integer number may return not zero in C/C++ ? Why does it depend on -O option of the compiler? For example this code gives 45 with -O0 and 0 with -O3 options in gcc 4.8.3: unsigned int x = 45; // 4 bytes x = x >> 32; printf("%u\n", x); Why it is like this? 回答1: Because it is undefined behavior: [expr.shift]

C - Using bit-shift operators for base conversion

不问归期 提交于 2019-12-10 14:55:07
问题 I'm trying to convert some data from hex to base64 in C, I found an algorithm online but I would really like to know how it works rather than just implenting it and firing it off. If someone could please explain how the following is working I would appreciate it. I have been reading about the shift operators and I don't seem to understand them as much as I thought I did...it's not quite clicking for me. for (x = 0; x < dataLength; x += 3) { /* these three 8-bit (ASCII) characters become one

Bitwise right shift >> in Objective-C

此生再无相见时 提交于 2019-12-10 13:49:55
问题 I have a variable (unsigned int) part_1 . If I do this: NSLog(@"%u %08x", part_1, part_1); (print unsigned value, and hex value) it outputs: 2063597568 7b000000 (only first two will have values). I want to convert this to 0000007b So i've tried doing unsigned int part_1b = part_1 >> 6 (and lots of variations) But this outputs: 32243712 01ec0000 Where am i going wrong? 回答1: You want to shift by 6*4 = 24 bits, not just 6 bits. Each '0' in the hex printf represents 4 bits. unsigned int part_1b =

Ctrl or Shift effects on the `onclick` event of an anchor tag in each browser

ぃ、小莉子 提交于 2019-12-10 13:43:36
问题 I recently discovered that different browsers handle the onclick event differently when the Control or Shift keys are pressed. They diverge similarly on behavior for for following links by clicking the middle mouse button. With the following link: <a href="http://www.example.com/" onclick="alert('onclick');">go to example.com</a> Onclick browser support table Mouse Keyboard Chrome Firefox Safari Opera IE5.5 IE6 IE7 IE8 IE9 Left None yes yes yes yes yes yes yes yes yes Left Ctrl yes yes yes

detect/get notification if shift key (modifier-key) pressed in uitextview

放肆的年华 提交于 2019-12-09 13:19:11
问题 I'm trying to figure out if there is any way in which we can detect if shift key is pressed or if any notification is sent when shift key is pressed in UIKeyboard - (BOOL) textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)string does not get called for shift key press since it is a modifier key. 回答1: Don't know whether you need to know it in combination with other text or only detect the single shift tap, but here is my solution for detecting