gt; project.org] On Behalf Of Karen Kotschy
> Sent: Tuesday, August 17, 2010 4:37 PM
> To: Dimitris Rizopoulos
> Cc: r-help@r-project.org
> Subject: Re: [R] replacing values in a vector
>
> Thanks so much to all those who suggested solutions! You guys are
> wonderful!
>
&g
Thanks so much to all those who suggested solutions! You guys are
wonderful!
I went with Dimitris' suggestion in the end.
Regards
Karen
On Tue 17Aug10, Dimitris Rizopoulos wrote:
> try this:
>
> vec <- c(3,2,6,4,7)
>
> n <- length(vec)
> for(i in seq_along(vec)){
> r <- numeric(n)
> r
try this:
vec <- c(3,2,6,4,7)
n <- length(vec)
for(i in seq_along(vec)){
r <- numeric(n)
r[i] <- vec[i]
assign(paste("vec.", letters[i], sep = ""), r)
}
I hope it helps.
Best,
Dimitris
On 8/17/2010 12:57 PM, Karen Kotschy wrote:
Dear helpRs
Does anyone have an elegant way of d
ugust 2010 12:58
To: r-help@r-project.org
Subject: [R] replacing values in a vector
Dear helpRs
Does anyone have an elegant way of doing the following:
For a given numeric vector, e.g. vec <- c(3,2,6,4,7)
Create a series of vectors where all but 1 of the values are replaced by
0's, e.g.
Try this:
mapply(function(x, y)assign(x, y, envir = globalenv()), sprintf('vec.%s',
letters[1:length(vec)]), split(diag(vec), 1:length(vec)))
On Tue, Aug 17, 2010 at 7:57 AM, Karen Kotschy wrote:
> Dear helpRs
>
> Does anyone have an elegant way of doing the following:
>
> For a given numeric v
Hi Karen,
Try this:
vec <- c(3,2,6,4,7)
res <- diag(vec)
k <- length(vect)
for(i in 1:k) assign(paste('vec', letters[i], sep = '.'), res[i,])
vec.a
# [1] 3 0 0 0 0
vec.b
# [1] 0 2 0 0 0
HTH,
Jorge
On Tue, Aug 17, 2010 at 6:57 AM, Karen Kotschy <> wrote:
> Dear helpRs
>
> Does anyone have an e
Dear helpRs
Does anyone have an elegant way of doing the following:
For a given numeric vector, e.g. vec <- c(3,2,6,4,7)
Create a series of vectors where all but 1 of the values are replaced by
0's, e.g.
vec.a <- c(3,0,0,0,0)
vec.b <- c(0,2,0,0,0)
vec.c <- c(0,0,6,0,0)
vec.d <- c(0,0,0,4,0)
Boy are you confused. This has nothing at all to do with substitution.
Instead do
test <- with(fc,ave.fc[match(diff_mirs_list,Probe)])
cheers,
Rolf Turner
On 7/11/2008, at 11:46 AM, Iain Gallagher wrote:
Hello list.
I have a vector of values:
eg
head(di
Hello list.
I have a vector of values:
eg
> head(diff_mirs_list)
[1] "hsa-miR-26b" "hsa-miR-26b" "hsa-miR-23a" "hsa-miR-27b" "hsa-miR-29a"
[6] "hsa-miR-29b"
and I would like to conditionally replace each value in this vector with a
number defined in a dataframe:
> fc
Probe ave.fc
9 matches
Mail list logo