Pass a vector of variables into lm() formula

You’re almost there. You just have to paste the entire formula together, something like this: paste(“roll_pct ~ “,b,sep = “”) coerce it to an actual formula using as.formula and then pass that to lm. Technically, I think lm may coerce a character string itself, but coercing it yourself is generally safer. (Some functions that expect … Read more

Intercept paste event in Javascript

You can intercept the paste event by attaching an “onpaste” handler and get the pasted text by using “window.clipboardData.getData(‘Text’)” in IE or “event.clipboardData.getData(‘text/plain’)” in other browsers. For example: var myElement = document.getElementById(‘pasteElement’); myElement.onpaste = function(e) { var pastedText = undefined; if (window.clipboardData && window.clipboardData.getData) { // IE pastedText = window.clipboardData.getData(‘Text’); } else if (e.clipboardData && … Read more

suppress NAs in paste()

For the purpose of a “true-NA”: Seems the most direct route is just to modify the value returned by paste2 to be NA when the value is “” paste3 <- function(…,sep=”, “) { L <- list(…) L <- lapply(L,function(x) {x[is.na(x)] <- “”; x}) ret <-gsub(paste0(“(^”,sep,”|”,sep,”$)”),””, gsub(paste0(sep,sep),sep, do.call(paste,c(L,list(sep=sep))))) is.na(ret) <- ret==”” ret } val<- paste3(c(“a”,”b”, “c”, … Read more

Combine several images horizontally with Python

You can do something like this: import sys from PIL import Image images = [Image.open(x) for x in [‘Test1.jpg’, ‘Test2.jpg’, ‘Test3.jpg’]] widths, heights = zip(*(i.size for i in images)) total_width = sum(widths) max_height = max(heights) new_im = Image.new(‘RGB’, (total_width, max_height)) x_offset = 0 for im in images: new_im.paste(im, (x_offset,0)) x_offset += im.size[0] new_im.save(‘test.jpg’) Test1.jpg Test2.jpg … Read more

Get current clipboard content? [closed]

Use the new clipboard API, via navigator.clipboard. It can be used like this: With async/await syntax: const text = await navigator.clipboard.readText(); Or with Promise syntax: navigator.clipboard.readText() .then(text => { console.log(‘Pasted content: ‘, text); }) .catch(err => { console.error(‘Failed to read clipboard contents: ‘, err); }); Keep in mind that this will prompt the user with … Read more