Re: [R] If (x 0)

2012-02-14 Thread ilai
: Re: [R] If (x 0) After placing res - conditional1(x) ; cat(result= ,res,\n) AFTER defining the function conditional1 (or R wouldn't know what conditional1 is), your script worked flawlessly for me. From the terminal in xubuntu10.04: $ R --no-save --slave --args 1 test1.R [1] 1 result=  1

[R] If (x 0)

2012-02-13 Thread Schmidt, Michael
Hi, I am new to R. I was trying to get a very simple program to run. Take one number from the command line. If the number 0 return -1. If number 0 return 1 and if the number == 0 return 0. The code is in a file called test1.R The code: #useage: R --no-save --args 5 test1.R args =

Re: [R] If (x 0)

2012-02-13 Thread jim holtman
Seems to work fine for me: conditional1 - function(x){ +result - 0 +if (x 0) { +result - 1 +} else if (x 0) { +result - -1 +} +return(result) + } conditional1(-1) [1] -1 conditional1(1) [1] 1 conditional1(0) [1] 0 On

Re: [R] If (x 0)

2012-02-13 Thread Henrik Bengtsson
Try adding --vanilla when calling R, e.g. R --vanilla --no-save --args 5 test1.R because I think you're picking up and previously stored session. You'll most likely will find that res - conditional1(x) will give an error saying 'conditional1' is not defined; you need to define the function

Re: [R] 0 x 0 matrix

2009-09-05 Thread Markku Karhunen
On 04-Sep-09 10:45:27, Markku Karhunen wrote: True. Should have read ?diag. However, this provokes a more general question: Is there some way I can declare some scalar and _all its functions_ as matrices? For instance, I would like to A = as.matrix(0.98) B = function(A) C = diag(sqrt(B))

Re: [R] 0 x 0 matrix

2009-09-05 Thread Ted Harding
On 05-Sep-09 10:00:26, Markku Karhunen wrote: On 04-Sep-09 10:45:27, Markku Karhunen wrote: True. Should have read ?diag. However, this provokes a more general question: Is there some way I can declare some scalar and _all its functions_ as matrices? For instance, I would like to A =

[R] 0 x 0 matrix

2009-09-04 Thread Markku Karhunen
Hi, Does anybody know, what is going on here? diag(sqrt(1)) [,1] [1,]1 diag(sqrt(0.)) 0 x 0 matrix sqrt(1) [1] 1 sqrt(0.) [1] 0.5773214 BR, Markku Karhunen researcher University of Helsinki __ R-help@r-project.org mailing

Re: [R] 0 x 0 matrix

2009-09-04 Thread Romain Francois
On 09/04/2009 12:25 PM, Markku Karhunen wrote: Hi, Does anybody know, what is going on here? diag(sqrt(1)) [,1] [1,] 1 diag(sqrt(0.)) 0 x 0 matrix sqrt(1) [1] 1 sqrt(0.) [1] 0.5773214 BR, Markku Karhunen researcher University of Helsinki Try this instead; diag(

Re: [R] 0 x 0 matrix

2009-09-04 Thread Duncan Murdoch
Markku Karhunen wrote: Hi, Does anybody know, what is going on here? diag( x ) produces a round(x) x round(x) identity matrix when x is length 1. (This is the third case listed on the man page ?diag). See the note there about a safer form if you wanted a matrix with x on the

Re: [R] 0 x 0 matrix

2009-09-04 Thread Barry Rowlingson
On Fri, Sep 4, 2009 at 11:25 AM, Markku Karhunenmarkku.karhu...@helsinki.fi wrote: Hi, Does anybody know, what is going on here? diag(sqrt(1))     [,1] [1,]    1 diag(sqrt(0.)) 0 x 0 matrix sqrt(1) [1] 1 sqrt(0.) [1] 0.5773214 Read the help for diag yet? 'diag'

Re: [R] 0 x 0 matrix

2009-09-04 Thread baptiste auguie
it's documented as unexpected ?diag Note Using diag(x) can have unexpected effects if x is a vector that could be of length one. Use diag(x, nrow = length(x)) for consistent behaviour. And the result follows from this part, else if (length(x) == 1L nargs() == 1L) { n -

Re: [R] 0 x 0 matrix

2009-09-04 Thread Duncan Murdoch
baptiste auguie wrote: it's documented as unexpected ?diag Note Using diag(x) can have unexpected effects if x is a vector that could be of length one. Use diag(x, nrow = length(x)) for consistent behaviour. And the result follows from this part, else if (length(x) == 1L nargs() == 1L)

Re: [R] 0 x 0 matrix

2009-09-04 Thread Duncan Murdoch
Duncan Murdoch wrote: baptiste auguie wrote: it's documented as unexpected ?diag Note Using diag(x) can have unexpected effects if x is a vector that could be of length one. Use diag(x, nrow = length(x)) for consistent behaviour. And the result follows from this part, else if

Re: [R] 0 x 0 matrix

2009-09-04 Thread Markku Karhunen
True. Should have read ?diag. However, this provokes a more general question: Is there some way I can declare some scalar and _all its functions_ as matrices? For instance, I would like to A = as.matrix(0.98) B = function(A) C = diag(sqrt(B)) so that all scalars are explicitly [1,1]

Re: [R] 0 x 0 matrix

2009-09-04 Thread Ted Harding
On 04-Sep-09 10:45:27, Markku Karhunen wrote: True. Should have read ?diag. However, this provokes a more general question: Is there some way I can declare some scalar and _all its functions_ as matrices? For instance, I would like to A = as.matrix(0.98) B = function(A) C =