search for: my_fun

Displaying 8 results from an estimated 8 matches for "my_fun".

Did you mean: my_func
2023 May 13
1
aggregate wind direction data with wind speed required
?s 15:51 de 13/05/2023, Stefano Sofia escreveu: > Dear list users, > > I have to aggregate wind direction data (wd) using a function that requires also a second input variable, wind speed (ws). > > This is the function that I need to use: > > > my_fun <- function(wd1, ws1){ > > u_component <- -ws1*sin(2*pi*wd1/360) > v_component <- -ws1*cos(2*pi*wd1/360) > mean_u <- mean(u_component, na.rm=T) > mean_v <- mean(v_component, na.rm=T) > mean_wd <- (atan2(mean_u, mean_v) * 360/2/pi) + 180 > re...
2023 May 13
2
aggregate wind direction data with wind speed required
Dear list users, I have to aggregate wind direction data (wd) using a function that requires also a second input variable, wind speed (ws). This is the function that I need to use: my_fun <- function(wd1, ws1){ u_component <- -ws1*sin(2*pi*wd1/360) v_component <- -ws1*cos(2*pi*wd1/360) mean_u <- mean(u_component, na.rm=T) mean_v <- mean(v_component, na.rm=T) mean_wd <- (atan2(mean_u, mean_v) * 360/2/pi) + 180 result <- mean_wd result } Does the a...
2011 Jul 17
1
function design: multiple imput names
dear all, a simple question, I need to write a function in which I retrive an undetermined number of vector in the function. I solved the problem thanks to this link http://stackoverflow.com/questions/2540232/how-to-allow-multiple-inputs-from-user-using-r so my function will look alike this my_fun <- function(...){ my_list <- lapply(..., function(x){x}) } I need just one more suggestion. how can give to each element of the list the name of the single variables I used as imput of "my_fun"?? I hope I was clear in what I want to do [[alternative HTML version deleted]]
2018 Mar 22
1
Calculate weighted proportions for several factors at once
...gt;% dplyr::count(var1, wt=wt) %>% mutate(prop1=n/sum(n)) df3 <- df1 %>% group_by(group) %>% dplyr::count(var2, wt=wt) %>% mutate(prop2=n/sum(n)) %>% left_join(df2, by='group') # I would like to do something like the following (which does of course not work): my_fun <- function(x,wt){ freq1 <- dplyr::count(x, wt=wt) prop1 <- freq1 / sum(freq1) return(prop) } df1 %>% group_by(group) %>% summarise_all(.funs=my_fun(.), .vars=c('var1', 'var2')) ############################################################ Best regards, Eri...
2007 Jan 18
4
How to optimize this loop ?
Dear R Users, I request your help to optimize a loop. Given a series of observations, I want to know how many consecutive past observations are below the last one. e.g : my_series <- c(3, 4, 10,14,8,3,4,6,9) As the last number (9) is higher than the four preceding numbers (6, 4, 3, 8), this function should return 4. my_series <- c(3, 4, 10,14,8,3,4,11,9) Here, it should return 0, as 9
2007 Apr 17
8
Verifying that a block calls a method
I have something like the following: def my_fun my_fun2 do raise Error end end I know that I can verify that the method receives my_fun2. How can I mock/stub out the example to verify that it calls raise Error? Scott
2009 Feb 11
1
Looping over a matrix passed to .C
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 I've written a function in R which takes a symmetrical matrix as input and processes all triplicate combinations of values from the matrix. The function looks something like: my_fun <- function(m) { if( nrow(mat) != ncol(mat) ) { stop("'m' must be a square matrix") } size <- nrow(m) for(x in 1:(size -2)) { for(y in (x+1):(size -1)) { xy <- m[x,y] for(z in (y+1):size ) { xz <- m[x,z] yz <- m[y,z]...
2013 Dec 12
2
internal manipulation of ...
Hello, I?m looking for examples on how to manipulate the ... internally, e.g. in a .Call or .External function. I?m particularly interested in accessing the environment in which each contribution to ... can be evaluated. So far, I?m using tricks involving passing down the sys.calls() and sys.frames() down to the C function. The documentation in