lapply

How to make a function in a for loop or lapply loop in a tabItem dashboard shiny

不羁的心 提交于 2019-12-02 07:13:16
I'm making a ShinyDashboard program and I have some troubles in finding a way to make a loop in the dashboardBody to catch MenuItems. This is a simple example of what I'm trying to fix: library(shiny) library(shinyjs) library(shinydashboard) VecNames=c("A","B","C","D","E") ui <- dashboardPage( dashboardHeader(title = "My Page"), dashboardSidebar(sidebarMenuOutput("sideBar_menu_UI")), dashboardBody( uiOutput("body_UI"), uiOutput("test_UI") ) ) server <- shinyServer(function(input, output, session) { output$sideBar_menu_UI <- renderMenu({ sidebarMenu(id = "sideBar_Menu", menuItem("Menu 1",

adjustOHLC - need solution to loop through character vector of tickers

回眸只為那壹抹淺笑 提交于 2019-12-02 06:19:11
问题 What I want to do is fairly easy but I haven't been able to figure it out. I thought I could do something similar to that outlined here I have a character vector of tickers that are xts OHLC objects returned by getSymbols . I want to loop through each ticker in symbols and pass the symbol to adjustOHLC to adjust for splits: symbols = c("FCX", "SPY") for(symbol in symbols){ return(adjustOHLC(symbol,adjust =c("split"), use.Adjusted=FALSE)) } It seems adjustOHLC does not grab the value of the

Joining the result of two statistical tables in one table in R

别说谁变了你拦得住时间么 提交于 2019-12-02 04:54:22
In continuation of this issue comparison Mann-Whitney test between groups , I decided to create a new topic. Solution of Rui Barradas helped me calculate Mann-Whitney for group 1-2 and 1-3. lst <- split(mydat, mydat$group) lapply(lst[-1], function(DF) wilcox.test(DF$var, lst[[1]]$var, exact = FALSE)) So now i want get the descriptive statistics. I use library:psych describeBy(mydat$var,mydat$group) So i get the following output group: 1 vars n mean sd median trimmed mad min max range skew kurtosis se X1 1 4 23.5 0.58 23.5 23.5 0.74 23 24 1 0 -2.44 0.29 -----------------------------------------

using lapply function and list in r

落爺英雄遲暮 提交于 2019-12-02 04:31:24
d1 <- data.frame(col_one = c(1,2,3),col_two = c(4, 5, 6)) d2 <- data.frame(col_one = c(1, 1, 1), col_two = c(6, 5, 4)) d3 <- data.frame(col_one = c(7, 1, 1), col_two = c(8, 5, 4)) my.list <- list(d1, d2,d3) for (i in 1:3) { table<- lapply(my.list, function(data, count) { sql <- #sqldf( paste0( "select *,count(col_one) from data where col_one = ", count," group by col_one" ) #) print(sql) }, count = i) } output: [1] "select *,count(col_one) from data where col_one = 1 group by col_one" [1] "select *,count(col_one) from data where col_one = 1 group by col_one" [1] "select *,count(col_one) from

display predicted values for initial data using auto.arima in R

馋奶兔 提交于 2019-12-02 02:57:02
Let's work with this data sample timeseries<-structure(list(Data = structure(c(10L, 14L, 18L, 22L, 26L, 29L, 32L, 35L, 38L, 1L, 4L, 7L, 11L, 15L, 19L, 23L, 27L, 30L, 33L, 36L, 39L, 2L, 5L, 8L, 12L, 16L, 20L, 24L, 28L, 31L, 34L, 37L, 40L, 3L, 6L, 9L, 13L, 17L, 21L, 25L), .Label = c("01.01.2018", "01.01.2019", "01.01.2020", "01.02.2018", "01.02.2019", "01.02.2020", "01.03.2018", "01.03.2019", "01.03.2020", "01.04.2017", "01.04.2018", "01.04.2019", "01.04.2020", "01.05.2017", "01.05.2018", "01.05.2019", "01.05.2020", "01.06.2017", "01.06.2018", "01.06.2019", "01.06.2020", "01.07.2017", "01.07

R: How to sum pairs in a Matrix by row?

强颜欢笑 提交于 2019-12-02 02:49:30
问题 Probably this would be easy. I have a Matrix: testM <- matrix(1:40, ncol = 4, byrow = FALSE) testM [,1] [,2] [,3] [,4] [1,] 1 11 21 31 [2,] 2 12 22 32 [3,] 3 13 23 33 [4,] 4 14 24 34 [5,] 5 15 25 35 [6,] 6 16 26 36 [7,] 7 17 27 37 [8,] 8 18 28 38 [9,] 9 19 29 39 [10,] 10 20 30 40 and I want to "reduce" the matrix summing column pairs by row. Expected result: [,1] [,2] [1,] 12 52 [2,] 14 54 [3,] 16 56 [4,] 18 58 [5,] 20 60 [6,] 22 62 [7,] 24 64 [8,] 26 66 [9,] 28 68 [10,] 30 70 I tried this

Non-standard evaluation in a user-defined function with lapply or with in R

梦想与她 提交于 2019-12-02 01:49:09
问题 I wrote a wrapper around ftable because I need to compute flat tables with frequency and percentage for many variables. As ftable method for class "formula" uses non-standard evaluation, the wrapper relies on do.call and match.call to allow the use of the subset argument of ftable (more details in my previous question). mytable <- function(...) { do.call(what = ftable, args = as.list(x = match.call()[-1])) # etc } However, I cannot use this wrapper with lapply nor with : # example 1: error

Non-standard evaluation in a user-defined function with lapply or with in R

梦想与她 提交于 2019-12-02 00:05:19
I wrote a wrapper around ftable because I need to compute flat tables with frequency and percentage for many variables. As ftable method for class "formula" uses non-standard evaluation, the wrapper relies on do.call and match.call to allow the use of the subset argument of ftable (more details in my previous question ). mytable <- function(...) { do.call(what = ftable, args = as.list(x = match.call()[-1])) # etc } However, I cannot use this wrapper with lapply nor with : # example 1: error with "lapply" lapply(X = warpbreaks[c("breaks", "wool", "tension")], FUN = mytable, row.vars = 1) Error

R: How to sum pairs in a Matrix by row?

跟風遠走 提交于 2019-12-02 00:01:36
Probably this would be easy. I have a Matrix: testM <- matrix(1:40, ncol = 4, byrow = FALSE) testM [,1] [,2] [,3] [,4] [1,] 1 11 21 31 [2,] 2 12 22 32 [3,] 3 13 23 33 [4,] 4 14 24 34 [5,] 5 15 25 35 [6,] 6 16 26 36 [7,] 7 17 27 37 [8,] 8 18 28 38 [9,] 9 19 29 39 [10,] 10 20 30 40 and I want to "reduce" the matrix summing column pairs by row. Expected result: [,1] [,2] [1,] 12 52 [2,] 14 54 [3,] 16 56 [4,] 18 58 [5,] 20 60 [6,] 22 62 [7,] 24 64 [8,] 26 66 [9,] 28 68 [10,] 30 70 I tried this but doesn't work X <- apply(1:(ncol(testM)/2), 1, function(x) sum(testM[x], testM[x+1]) ) Error in apply

Can lapply pass (to a function) values stored in a vector, successively

落爺英雄遲暮 提交于 2019-12-01 19:37:33
I need lapply to pass (to a function) values stored in a vector, successively. values <- c(10,11,13,10) lapply(foo,function(x) peakabif(x,npeaks=values)) So to get : peakabif(x1,npeaks=10) peakabif(x2,npeaks=11) peakabif(x3,npeaks=13) peakabif(x4,npeaks=10) Is this possible or do I need to reconsider using lapply ? Is a for loop inside the function would work ? You want to use mapply for this: mapply(peakabif, x=foo, npeaks=values) There are a couple of ways to handle this. You could try a straight indexing vector approach. lapply(1:length(foo), function(i) peakabif(foo[i], npeaks=values[i]))