: 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
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 =
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
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
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))
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 =
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
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(
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
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'
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 -
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)
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
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]
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 =
15 matches
Mail list logo