mapply Questions

3

Solved

I want to calculate growing degree days with several bases, using minimum daily temp, and maximum daily temp. I would like to do this without a for loop if possible to minimize my code. bases <-...
Ida asked 6/10 at 21:17

4

Solved

I have the following data.table x = structure(list(f1 = 1:3, f2 = 3:5), .Names = c("f1", "f2"), row.names = c(NA, -3L), class = c("data.table", "data.frame")) I would like to apply a function to...
Spragens asked 21/8, 2014 at 16:26

2

I would like to be able to apply a function to all combinations of a set of input arguments. I have a working solution (below) but would be surprised if there's not a better / more generic way to d...
Rain asked 18/9, 2014 at 11:27

1

Solved

I understood that data.table is not copied when returned from a function. However, in this particular case it does get copied. Can one explain why? dt1 <- data.table(a=1) dt2 <- data.table(b...
Renatorenaud asked 21/1, 2016 at 12:44

3

Solved

I can not use the subset argument of xtabs or aggregate (or any function I tested, including ftable and lm) with mapply. The following calls fail with the subset argument, but they work without: m...
Multipara asked 29/6, 2019 at 13:36

3

Solved

Using base R, I'd like to use the mapply function on a nested list. For example, in the code below, I'm trying to remove the letter "a" from each element of a nested list. I'd like to replace the l...
Appalling asked 8/4, 2020 at 17:18

2

Solved

I need to programmatically apply different functions to different columns and group by, using data.table. If the columns and functions were known, I would do like this: library(data.table) DT = ...
Abstractionist asked 26/11, 2019 at 21:39

2

Solved

I have the following list and vectors of parameters: myList <- list(c(3, 0, 1), c(2, 2, 2)) vPar1 <- c(1, 5, 100) vPar2 <- c(100, 5, 1) and I'm trying to draw samples from 3 Beta distri...
Cocaine asked 25/11, 2019 at 21:12

2

Solved

I would like to pass a function name as an argument in mapply: f2 <- function(a, b) a + b^2 f <- function(a, b, func) func(a, b) f(1, 3, f2) ## returns 10 mapply(f2, 1:2, 3) ## returns [1] 1...
Earsplitting asked 25/10, 2019 at 15:8

4

I want to remove multiple patterns from multiple character vectors. Currently I am going: a.vector <- gsub("@\\w+", "", a.vector) a.vector <- gsub("http\\w+", "", a.vector) a.vector <- g...
Wipe asked 13/3, 2015 at 16:8

1

How do I use MoreArgs properly with chart_Series? p.txt s,n ABBV,AbbVie BMY,Bristol LLY,EliLily MRK,Merck PFE,Pfizer sof.r # R --silent --vanilla < sof.r library(quantmod) options("getSymbo...
Humphreys asked 14/7, 2019 at 0:57

2

Solved

Due to memory (and speed) issues, I was hoping to do some computations inside a data.table instead of doing them outside it. The following code has 100.000 rows, but I'm working with 40 million r...
Brunella asked 12/7, 2019 at 23:58

2

Solved

I want to do what seems a straightforward application of mapply in a data table. I want to multiply a series of data table columns by the value in another column. Here's my function. y is the singl...
Hebraist asked 25/4, 2018 at 16:32

1

Solved

I think I've missed something simple here: I have a list of data.frames, and a list of row numbers to select. Something like this: a <- data.frame(q = c(1,0,0,0), w = c(1,1,0,0), e = c(1,1,1...
Soothe asked 5/1, 2018 at 3:27

1

Solved

I have a database of employees, with their manager's id, in long format (one row per employee per month). I would like to add a column that contains their manager's manager's id (or the id of their...
Crapulent asked 29/8, 2016 at 16:16

3

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 ...
Bespoke asked 12/2, 2016 at 0:20

1

Solved

Consider this toy function that receives 3 arguments: toy <- function(x, y, z){ paste(x, y, z) } For each argument I have a number of values (not necessarily the same number for each argumen...
Fallen asked 9/3, 2016 at 11:12

5

Solved

So in the course of generating some fake data to answer a map question, I found myself writing the following: # Generate some fake data lat <- seq(-90, 90, by = 5) lon <- seq(-180, 180, by =...
Mensural asked 24/2, 2016 at 9:48

3

Solved

I am trying to use a data.table within a function, and I am trying to understand why my code is failing. I have a data.table as follows: DT <- data.table(my_name=c("A","B","C","D","E","F"),my_i...
Giesecke asked 25/6, 2015 at 13:34

2

Solved

(Related question that does not include sorting. It's easy to just use paste when you don't need to sort.) I have a less-than-ideally-structured table with character columns that are generic "item...
Botanomancy asked 25/2, 2015 at 21:40

2

Solved

I am trying to apply functions described here for a set of time series. For this, mapply seems to be a good approach but I guess there is some problem either in defining the function or in using ma...
Runaway asked 24/8, 2014 at 23:6

5

Solved

Say I have two vectors: a <- c("george", "harry", "harry", "chris", "steve", "steve", "steve", "harry") b <- c(...
Squally asked 31/8, 2014 at 2:19

2

Solved

The Vectorize() and the apply() functions in R can often be used to accomplish the same goal. I usually prefer vectorizing a function for readability reasons, because the main calling function is r...
Osterhus asked 1/8, 2014 at 13:40

3

Solved

Let x<-2 in the global env: x <-2 x [1] 2 Let a be a function that defines another x locally and uses get: a<-function(){ x<-1 get("x") } This function correctly gets x from th...
Stoneman asked 15/4, 2014 at 14:17

1

Solved

To find the row-wise correlation of two matrices X and Y, the output should have a correlation value for row 1 of X and row 1 of Y, ..., hence in total ten values (because there are ten rows): X &...
Erythroblastosis asked 25/9, 2013 at 10:25

© 2022 - 2024 — McMap. All rights reserved.