multiple-arguments

R: apply a function to every element of two variables respectively

旧城冷巷雨未停 提交于 2019-11-29 19:56:30
问题 I have a function with two variables x and y: fun1 <- function(x,y) { z <- x+y return(z) } The function work fine by itself: fun1(15,20) But when I try to use it with two vectors for x and y with an apply function I do not get the correct 56*121 array Lx <- c(1:56) Ly <- c(1:121) mapply(fun1, Lx, Ly) I would be grateful for your help and also on advice on the fastest solution (eg is a data.table or dplyr solution faster than apply). 回答1: If you want to use mapply() you have to provide it with

Using the same option multiple times in Python's argparse

痴心易碎 提交于 2019-11-28 20:02:37
I'm trying to write a script that accepts multiple input sources and does something to each one. Something like this ./my_script.py \ -i input1_url input1_name input1_other_var \ -i input2_url input2_name input2_other_var \ -i input3_url input3_name # notice inputX_other_var is optional But I can't quite figure out how to do this using argparse . It seems that it's set up so that each option flag can only be used once. I know how to associate multiple arguments with a single option ( nargs='*' or nargs='+' ), but that still won't let me use the -i flag multiple times. How do I go about

Using the same option multiple times in Python's argparse

不打扰是莪最后的温柔 提交于 2019-11-27 12:38:32
问题 I'm trying to write a script that accepts multiple input sources and does something to each one. Something like this ./my_script.py \ -i input1_url input1_name input1_other_var \ -i input2_url input2_name input2_other_var \ -i input3_url input3_name # notice inputX_other_var is optional But I can't quite figure out how to do this using argparse . It seems that it's set up so that each option flag can only be used once. I know how to associate multiple arguments with a single option ( nargs='*