Displaying 20 results from an estimated 10000 matches similar to: "An extention of outer() ?"
2011 Apr 26
2
Undestanding return()
Here, I have following generic function:
Fn1 <- function(x) {
........
return(x) # assume x is calculated in previous steps
.........
return(y) # assume y is calculated in previous steps
..........
return(z) # assume z is calculated in previous steps
}
In this case what fn1
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 14
3
How to see inside of this function?
Hi, there is a function Skewness() under fBasics package. If I type
"skewness", I get followings:
> skewness
function (x, ...)
{
UseMethod("skewness")
}
<environment: namespace:timeDate>
Would be great if someone tell me how to see the codes of this function.
2ndly suppose I create following function:
fn1 <- function(x) return(x+2)
How
2011 Feb 01
1
Working with additional input for user defined function
Hi all, suppose I have following user defined function:
fn1 = function(x, y, ...) {
z <- x+y; u=y^2
# if something with name "add" exists in the
function argument then do some calculation and return that calculated value,
NOT z
# if NOT then return z
2011 Mar 11
3
'Date' elements within a matrix
Dear all, when I put date objects (class of 'Date') in a matrix it becomes
numeric:
> dat <- matrix(seq(as.Date("2011-01-01"), as.Date("2011-01-09"), by="1
day"), 3)
> dat
[,1] [,2] [,3]
[1,] 14975 14978 14981
[2,] 14976 14979 14982
[3,] 14977 14980 14983
> class(dat[1,1])
[1] "numeric"
As it could not preserve the
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
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 ==
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
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 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
2011 Jan 21
3
How to look into the asterisked function?
Hi friends, there is methods() function to see the all available methods for
a particular function, for example:
> head(methods("print"))
[1] "print.acf" "print.anova" "print.aov" "print.aovlist"
"print.ar" "print.Arima"
In this list, there are some functions which are asterisked like
print.acf().
2012 Dec 18
7
Summarizing elements for a data.frame
Hello again, let say we have following data:
Dat1 <- structure(list(factor.sample.LETTERS.1.3...6..replace...T.. =
structure(c(1L,
3L, 2L, 1L, 3L, 3L), .Label = c("A", "B", "C"), class = "factor"),
factor.sample.letters.1.2...6..replace...T.. = structure(c(2L,
2L, 1L, 1L, 2L, 1L), .Label = c("a", "b"), class =