Dear all,
Thanks very much for your help. This completely clarifies my question.
Mayteo
Il giorno 23/dic/2015 17:05, "Anthoni, Peter (IMK)"
ha scritto:
> Hi,
>
> How about the following:
> foo2 <- function(s,i,j,value)
> {
> M = get(paste("M_",s,sep=""))
> M[i,j] = value
> assign(paste("M_"
> On Dec 23, 2015, at 12:44 AM, Matteo Richiardi
> wrote:
>
> I am following the example I find on ?assign:
>
> a <- 1:4
> assign("a[1]", 2)
You appear to have completely misinterpreted the intent of the authors of that
help page. The next two lines in that example (which you omitted) show
Hamilton, Ontario
Canada L8S 4M4
Web: socserv.mcmaster.ca/jfox
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Matteo
> Richiardi
> Sent: December 23, 2015 3:45 AM
> To: r-help@r-project.org
> Subject: [R] assigning values to elements
Hi,
How about the following:
foo2 <- function(s,i,j,value)
{
M = get(paste("M_",s,sep=""))
M[i,j] = value
assign(paste("M_",s,sep=""),M, envir = .GlobalEnv)
}
foo2("a",1,2,15)
cheers
Peter
> On 23 Dec 2015, at 09:44, Matteo Richiardi wrote:
>
> I am following the example I find on ?ass
I think this may help.
my_assign <- function(operand, value) {
assignment <- paste(operand, value, sep = "<-")
e <- parse(text = assignment)
eval.parent(e)
}
a <- rep(0,5)
> a
[1] 0 0 0 0 0
my_assign("a[2]", 7)
> a
[1] 0 7 0 0 0
my_assign("a[4]", 12)
> a
[1] 0 7 0 12 0
--
GG
15 9:45 AM
> To: r-help@r-project.org
> Subject: [R] assigning values to elements of matrixes
>
> I am following the example I find on ?assign:
>
> a <- 1:4
> assign("a[1]", 2)
>
> This appears to create a new variable named "a[1]" rather than changin
I am following the example I find on ?assign:
a <- 1:4
assign("a[1]", 2)
This appears to create a new variable named "a[1]" rather than
changing the value of the vector.
Am I missing something here? How can I assign a value to a specified
element of a vector/matrix?
Of course, my problem is sli
7 matches
Mail list logo