similar to: Need help on matrix calculation

Displaying 20 results from an estimated 10000 matches similar to: "Need help on matrix calculation"

2013 Apr 17
2
On matrix calculation
Hello again, Let say I have a matrix: Mat <- matrix(1:12, 4, 3) And a vector: Vec <- 5:8 Now I want to do following: Each element of row-i in 'Mat' will be divided by i-th element of Vec Is there any direct way to doing that? Thanks for your help
2013 Jan 24
2
Question on matrix calculation
Hello again, Ley say I have 1 matrix and 1 data frame: > mat <- matrix(1:15, 5) > match_df <- data.frame(Seq = 1:5, criteria = sample(letters[1:5], 5, replace = T)) > mat [,1] [,2] [,3] [1,] 1 6 11 [2,] 2 7 12 [3,] 3 8 13 [4,] 4 9 14 [5,] 5 10 15 > match_df Seq criteria 1 1 c 2 2 e 3 3 c 4 4 c 5
2010 Sep 14
5
Problem with cat()
Dear all, I have a problem with the cat() function. Let say I have following: fn1 <- function(n = 5){ mat <- matrix(rnorm(5*5), 5, 5) cat(as.character(mat)) return(n) } However when I run above function I get this: > fn1() -0.601930631438248 -1.16950049447942 0.469257329394626 -1.39766868242906 -1.02580943892082 1.4067931110327 -1.07245318857022 -0.0205043699310245 0.234628727206755
2010 Jul 10
7
Need help on date calculation
Hi all, please see my code: > library(zoo) > a <- as.yearmon("March-2010", "%B-%Y") > b <- as.yearmon("May-2010", "%B-%Y") > > nn <- (b-a)*12 # number of months in between them > nn [1] 2 > as.integer(nn) [1] 1 What is the correct way to find the number of months between "a" and "b", still
2012 Feb 08
2
Memory allocation problem (again!)
Dear all, I know this problem was discussed many times in forum, however unfortunately I could not find any way out for my own problem. Here I am having Memory allocation problem while generating a lot of random number. Here is my description: > rnorm(50000*6000) Error: cannot allocate vector of size 2.2 Gb In addition: Warning messages: 1: In rnorm(50000 * 6000) : Reached total allocation
2013 Mar 09
4
Calculation with date
Hello again, Let say I have an non-negative integer vector (which may be random): Vec <- c(0, 13, 10, 4) And I have a date: > Date <- as.Date(Sys.time()) > Date [1] "2013-03-09" Using these 2 information, I want to get following date-vector: New_Vec <- c("2013-03-01", "2014-04-01", "2014-01-01", "2013-07-01") Basically the
2011 Apr 06
2
A zoo related question
Dear all, please consider my following workbook: library(zoo) lis1 <- vector('list', length = 2) lis2 <- vector('list', length = 2) lis1[[1]] <- zooreg(rnorm(20), start = as.Date("2010-01-01"), frequency = 1) lis1[[2]] <- zooreg(rnorm(20), start = as.yearmon("2010-01-01"), frequency = 12) lis2[[1]] <- matrix(1:40, 20) lis2[[2]] <-
2018 Mar 04
3
Change Function based on ifelse() condtion
Below is my full implementation (tried to make it simple as for demonstration) Lapply_me = function(X = X, FUN = FUN, Apply_MC = FALSE, ...) { if (Apply_MC) { return(mclapply(X, FUN, ...)) } else { if (any(names(list(...)) == 'mc.cores')) { myList = list(...)[!names(list(...)) %in% 'mc.cores'] } return(lapply(X, FUN, myList)) } } Lapply_me(as.list(1:4), function(xx) { if (xx ==
2018 Mar 04
0
Change Function based on ifelse() condtion
The reason that it works for Apply_MC=TRUE is that in that case you call mclapply(X,FUN,...) and the mclapply() function strips off the mc.cores argument from the "..." list before calling FUN, so FUN is being called with zero arguments, exactly as it is declared. A quick workaround is to change the line Lapply_me(as.list(1:4), function(xx) { to Lapply_me(as.list(1:4),
2018 Mar 04
2
Change Function based on ifelse() condtion
My modified function looks below : Lapply_me = function(X = X, FUN = FUN, Apply_MC = FALSE, ...) { if (Apply_MC) { return(mclapply(X, FUN, ...)) } else { if (any(names(list(...)) == 'mc.cores')) { myList = list(...)[!names(list(...)) %in% 'mc.cores'] } return(lapply(X, FUN, myList)) } } Here, I am not passing ... anymore rather passing myList On Sun, Mar 4, 2018 at 10:37 PM,
2018 Mar 04
2
Change Function based on ifelse() condtion
@Eric - with this approach I am getting below error : Error in FUN(X[[i]], ...) : unused argument (list()) On Sun, Mar 4, 2018 at 10:18 PM, Eric Berger <ericjberger at gmail.com> wrote: > Hi Christofer, > You cannot assign to list(...). You can do the following > > myList <- list(...)[!names(list(...)) %in% 'mc.cores'] > > HTH, > Eric > > On Sun, Mar
2012 Apr 10
1
Double precision calculation
Dear all, Does R use double precision for calculation as default? If not, how to enforce double precision calculation in R for my current calculation session? I Use R-2.14.0 with windows XP. Thanks,
2012 Dec 14
5
A question on list and lapply
Dear all, let say I have following list: Dat <- vector("list", length = 26) names(Dat) <- LETTERS My_Function <- function(x) return(rnorm(5)) Dat1 <- lapply(Dat, My_Function) However I want to apply my function 'My_Function' for all elements of 'Dat' except the elements having 'names(Dat) == "P"'. Here I have specified the name
2017 Aug 02
4
Extracting numeric part from a string
Hi again, I am struggling to extract the number part from below string : "\"cm_ffm\":\"563.77\"" Basically, I need to extract 563.77 from above. The underlying number can be a whole number, and there could be comma separator as well. So far I tried below : > library(stringr) > str_extract("\"cm_ffm\":\"563.77\"",
2012 Mar 16
4
How to start R in maximized size???
Dear all, when I start R, I want that the console window should be in the Maximized size automatically. Can somebody help me how to achieve that? Thanks and regards,
2013 Mar 28
4
How to replace '$' sign?
Hello again, I want to remove "$" sign and replace with nothing in my text. Therefore I used following code: > gsub("$|,", "", "$232,685.35436") [1] "$232685.35436" However I could not remove '$' sign. Can somebody help me why is it so? Thanks and regards
2018 Mar 04
0
Change Function based on ifelse() condtion
That's fine. The issue is how you called Lapply_me(). What did you pass as the argument to FUN? And if you did not pass anything that how is FUN declared? You have not shown that in your email. On Sun, Mar 4, 2018 at 7:11 PM, Christofer Bogaso < bogaso.christofer at gmail.com> wrote: > My modified function looks below : > > Lapply_me = function(X = X, FUN = FUN, Apply_MC =
2017 Aug 10
3
Zoo rolling window with increasing window size
Hi Joshua, thanks for your prompt reply. However as I said, sum() function I used here just for demonstrating the problem, I have other custom function to implement, not necessarily sum() I am looking for a generic solution for above problem. Any better idea? Thanks, On Fri, Aug 11, 2017 at 12:04 AM, Joshua Ulrich <josh.m.ulrich at gmail.com> wrote: > Use a `width` of integer index
2011 Nov 10
5
A question on Programming
Dear all. Let say I have a group of codes which will be used in many places in my overall R-code files. These group of codes will be used within a for-loop (with a big length, like 10000 times) and also many other places outside of that for loop. As this group of codes are being used in many places, I thought to put them within a user-defined function. Here my question is, is there any speed
2012 Apr 12
2
How to calculate the "McFadden R-square" for LOGIT model?
Dear all, can somebody please help me how to calculate "McFadden R-square" for a LOGIT model? Corresponding definition can be found here: http://publib.boulder.ibm.com/infocenter/spssstat/v20r0m0/index.jsp?topic=%2Fcom.ibm.spss.statistics.help%2Falg_plum_statistics_rsq_mcfadden.htm Here is my data: Data <- structure(c(1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1,