Questions tagged as 'apply'

2
answers

Apply, sapply, mapply, lapply, vapply, rapply, tapply, replicate, aggregate, by and correlates in R. When and how to use?

What is the difference between the functions apply , sapply , mapply , lapply , vapply , rapply , tapply , replicate , aggregate , by and correlates no R? When and how to use each o...
asked by 04.03.2014 / 23:52
2
answers

Somatoria accumulating columns in a matrix in R

I have the following situation: In a numeric matrix type: Temp <- matrix(runif(25, 10, 100),nrow=5,ncol=5) V1 V2 V3 V4 V5 11 34 45 54 55 16 21 45 75 61 88 49 85 21 22 12 13 12 11...
asked by 25.04.2016 / 23:10
2
answers

* apply with three-argument functions in R

I've created a three-argument function and I want to apply it to a 200 X 3 matrix where on each line are the three arguments I need to use in the function. As a result I would get a vector of size 200. How can I do this?     
asked by 27.06.2014 / 07:44
2
answers

How to execute the tapply function for multiple dataframes in R?

I want to execute only ONE tapply function and get results for each of the dataframes at one time: dataset1<-data.frame(group = rep(c('a','b','c','d'), 3, each = 3), number1 = c(1:36), number2 = c(1:36)) dataset...
asked by 18.08.2018 / 04:28
1
answer

How to swap an apply within a for by a double apply?

I have a origem vector and a destino vector with several locations in latitude and longitude. For each location in origem , I want to count how many places in destino are located within a radius of up to 2km, so I d...
asked by 18.01.2017 / 01:16
1
answer

Apply a function using some columns of all rows in a Dataframe (r)

I have the following Dataframe: AVG_VOLUME AVG_RETURN VOL PRICE SPX Index 500000 0.01 0.08 2082 KR7000270009 6000 0.02 0.09 102 KR7005930003 7000 0.02 0.08...
asked by 15.04.2016 / 21:34
1
answer

What is the logic of function (x) and function (x, y) in R?

When executing loops with apply functions, function(x) is always used. Example: lapply(df,function(x)gsub('[^A-Z]','',x)) In other functions, however, function(x,y) is used. Example: Reduce(function(x,y)merge(x,y,all=TRUE,b...
asked by 21.09.2018 / 20:14
2
answers

How to add a same substring across multiple columns in R

I have a base with 2 rows and 68 observations called "varnomes" and would like to add the word "PF" at the end of each observation. With this, I tried to use the paste function: varnomes<-paste(varnomes,"PF") But I did not succeed. Th...
asked by 13.03.2017 / 21:34
1
answer

Preserve 'rownames' after use of family functions apply

I use the apply functions, and I need to have rownames left in the database after executing them. Consider: dataframe=structure(list(Composição100g = structure(c("Valor energético (KJ)", "Proteína", "Glicídios", "Açúcar", "Amido...
asked by 15.09.2018 / 19:57
1
answer

How to use the xmlSApply with separator?

I used xmlSApply and would like to get the result with a separator but could not apply. Below is an example so that they can reproduce: library(XML) fileUrl <- "http://www.w3schools.com/xml/simple.xml" doc <- xmlTreeParse(fileU...
asked by 20.10.2014 / 16:26