paste

suppress NAs in paste()

删除回忆录丶 提交于 2019-11-26 14:37:26
Regarding the bounty Ben Bolker 's paste2 -solution produces a "" when the strings that are pasted contains NA 's in the same position. Like this, > paste2(c("a","b", "c", NA), c("A","B", NA, NA)) [1] "a, A" "b, B" "c" "" The fourth element is an "" instead of an NA Like this, [1] "a, A" "b, B" "c" NA I'm offering up this small bounty for anyone who can fix this. Original question I've read the help page ?paste , but I don't understand how to have R ignore NA s. I do the following, foo <- LETTERS[1:4] foo[4] <- NA foo [1] "A" "B" "C" NA paste(1:4, foo, sep = ", ") and get [1] "1, A" "2, B" "3,

How to use reference variables by character string in a formula?

血红的双手。 提交于 2019-11-26 13:06:46
In the minimal example below, I am trying to use the values of a character string vars in a regression formula. However, I am only able to pass the string of variable names ("v2+v3+v4") to the formula, not the real meaning of this string (e.g., "v2" is dat$v2). I know there are better ways to run the regression (e.g., lm(v1 ~ v2 + v3 + v4, data=dat) ). My situation is more complex, and I am trying to figure out how to use a character string in a formula. Any thoughts? Updated below code # minimal example # create data frame v1 <- rnorm(10) v2 <- sample(c(0,1), 10, replace=TRUE) v3 <- rnorm(10)

Concatenate row-wise across specific columns of dataframe

放肆的年华 提交于 2019-11-26 09:31:11
问题 I have a data frame with columns that, when concatenated (row-wise) as a string, would allow me to partition the data frame into a desired form. > str(data) \'data.frame\': 680420 obs. of 10 variables: $ A : chr \"2011-01-26\" \"2011-01-26\" \"2011-02-09\" \"2011-02-09\" ... $ B : chr \"2011-01-26\" \"2011-01-27\" \"2011-02-09\" \"2011-02-10\" ... $ C : chr \"2011-01-26\" \"2011-01-26\" \"2011-02-09\" \"2011-02-09\" ... $ D : chr \"AAA\" \"AAA\" \"BCB\" \"CCC\" ... $ E : chr \"A00001\" \

jQuery bind to Paste Event, how to get the content of the paste

放肆的年华 提交于 2019-11-26 09:29:33
问题 I have a jquery token tagit plugin and I want to bind to the paste event to add items correctly. I\'m able to bind to the paste event like so: .bind(\"paste\", paste_input) ... function paste_input(e) { console.log(e) return false; } How can I obtain the actual pasted content value? 回答1: There is an onpaste event that works in modern day browsers. You can access the pasted data using the getData function on the clipboardData object. $("#textareaid").bind("paste", function(e){ // access the

Pass a vector of variables into lm() formula

只愿长相守 提交于 2019-11-26 04:19:26
问题 I was trying to automate a piece of my code so that programming become less tedious. Basically I was trying to do a stepwise selection of variables using fastbw() in the rms package. I would like to pass the list of variables selected by fastbw() into a formula as y ~ x1+x2+x3 , \"x1\" \"x2\" \"x3\" being the list of variables selected by fastbw() Here is the code I tried and did not work olsOAW0.r060 <- ols(roll_pct~byoy+trans_YoY+change18m, subset= helper==\"POPNOAW0_r060\", na.action = na

How to use reference variables by character string in a formula?

时光怂恿深爱的人放手 提交于 2019-11-26 03:38:05
问题 In the minimal example below, I am trying to use the values of a character string vars in a regression formula. However, I am only able to pass the string of variable names (\"v2+v3+v4\") to the formula, not the real meaning of this string (e.g., \"v2\" is dat$v2). I know there are better ways to run the regression (e.g., lm(v1 ~ v2 + v3 + v4, data=dat) ). My situation is more complex, and I am trying to figure out how to use a character string in a formula. Any thoughts? Updated below code #

How to use reference variables by character string in a formula?

房东的猫 提交于 2019-11-26 03:11:12
问题 In the minimal example below, I am trying to use the values of a character string vars in a regression formula. However, I am only able to pass the string of variable names (\"v2+v3+v4\") to the formula, not the real meaning of this string (e.g., \"v2\" is dat$v2). I know there are better ways to run the regression (e.g., lm(v1 ~ v2 + v3 + v4, data=dat) ). My situation is more complex, and I am trying to figure out how to use a character string in a formula. Any thoughts? Updated below code #

Intercept paste event in Javascript

时光毁灭记忆、已成空白 提交于 2019-11-26 03:10:21
问题 Is there a way to intercept the paste event in JavaScript and get the raw value, change it, and set the associated DOM element\'s value to be the modified value? For instance, I have a user trying to copy and paste a string with spaces in it and the string\'s length exceeds the max length of my text box. I want to intercept the text, remove the spaces, and then set the text box\'s value with the change value. Is this possible? 回答1: You can intercept the paste event by attaching an "onpaste"

suppress NAs in paste()

一个人想着一个人 提交于 2019-11-26 02:57:50
问题 Regarding the bounty Ben Bolker\'s paste2 -solution produces a \"\" when the strings that are pasted contains NA \'s in the same position. Like this, > paste2(c(\"a\",\"b\", \"c\", NA), c(\"A\",\"B\", NA, NA)) [1] \"a, A\" \"b, B\" \"c\" \"\" The fourth element is an \"\" instead of an NA Like this, [1] \"a, A\" \"b, B\" \"c\" NA I\'m offering up this small bounty for anyone who can fix this. Original question I\'ve read the help page ?paste , but I don\'t understand how to have R ignore NA s

Combine several images horizontally with Python

做~自己de王妃 提交于 2019-11-26 02:17:47
问题 I am trying to horizontally combine some JPEG images in Python. Problem I have 3 images - each is 148 x 95 - see attached. I just made 3 copies of the same image - that is why they are the same. My attempt I am trying to horizontally join them using the following code: import sys from PIL import Image list_im = [\'Test1.jpg\',\'Test2.jpg\',\'Test3.jpg\'] new_im = Image.new(\'RGB\', (444,95)) #creates a new empty image, RGB mode, and size 444 by 95 for elem in list_im: for i in xrange(0,444,95