Re: [R] how to replace values in a named vector

2020-09-14 Thread Rui Barradas

Hello,

Please Ana, post data in dput format.
And the expected output too.

Hope this helps,

Rui Barradas

Às 17:37 de 14/09/20, Ana Marija escreveu:

sorry not replace with NA but with empty string for a name, for example

for example this:


geneSymbol["Ku8QhfS0n_hIOABXuE"]

Ku8QhfS0n_hIOABXuE
"MACC1"

would go when I subject it to


geneSymbol["Ku8QhfS0n_hIOABXuE"]


Ku8QhfS0n_hIOABXuE

On Mon, Sep 14, 2020 at 11:35 AM Ana Marija  wrote:


Hello,

I have a vector like this:


head(geneSymbol)

Ku8QhfS0n_hIOABXuE Bx496XsFXiAlj.Eaeo W38p0ogk.wIBVRXllY
QIBkqIS9LR5DfTlTS8 BZKiEvS0eQ305U0v34 6TheVd.HiE1UF3lX6g
"MACC1""GGACT"   "A4GALT"
"NPSR1-AS1""NPSR1-AS1" "AAAS"

it has around 15000 entries. How do I replace all values with NA
expect these that are named like this:

geneSymbol[c("0lQ1XozriVZTn.PezY","uaeFiCdegrnWFijF_s","ZOluqaxSe3ndekoNng","912ny6eCHjnlY2XSCU","odF3XHR8CVl4SAUaUQ")]



geneSymbol[c("0lQ1XozriVZTn.PezY","uaeFiCdegrnWFijF_s","ZOluqaxSe3ndekoNng","912ny6eCHjnlY2XSCU","odF3XHR8CVl4SAUaUQ")]

0lQ1XozriVZTn.PezY uaeFiCdegrnWFijF_s ZOluqaxSe3ndekoNng
912ny6eCHjnlY2XSCU odF3XHR8CVl4SAUaUQ
 "FLCN" "FLCN" "FLCN"
"UCA1" "IL1B"

Thanks
Ana


__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to replace values in a named vector

2020-09-14 Thread Ana Marija
sorry not replace with NA but with empty string for a name, for example

for example this:

> geneSymbol["Ku8QhfS0n_hIOABXuE"]
Ku8QhfS0n_hIOABXuE
   "MACC1"

would go when I subject it to

> geneSymbol["Ku8QhfS0n_hIOABXuE"]

Ku8QhfS0n_hIOABXuE

On Mon, Sep 14, 2020 at 11:35 AM Ana Marija  wrote:
>
> Hello,
>
> I have a vector like this:
>
> > head(geneSymbol)
> Ku8QhfS0n_hIOABXuE Bx496XsFXiAlj.Eaeo W38p0ogk.wIBVRXllY
> QIBkqIS9LR5DfTlTS8 BZKiEvS0eQ305U0v34 6TheVd.HiE1UF3lX6g
>"MACC1""GGACT"   "A4GALT"
> "NPSR1-AS1""NPSR1-AS1" "AAAS"
>
> it has around 15000 entries. How do I replace all values with NA
> expect these that are named like this:
>
> geneSymbol[c("0lQ1XozriVZTn.PezY","uaeFiCdegrnWFijF_s","ZOluqaxSe3ndekoNng","912ny6eCHjnlY2XSCU","odF3XHR8CVl4SAUaUQ")]
>
>
> > geneSymbol[c("0lQ1XozriVZTn.PezY","uaeFiCdegrnWFijF_s","ZOluqaxSe3ndekoNng","912ny6eCHjnlY2XSCU","odF3XHR8CVl4SAUaUQ")]
> 0lQ1XozriVZTn.PezY uaeFiCdegrnWFijF_s ZOluqaxSe3ndekoNng
> 912ny6eCHjnlY2XSCU odF3XHR8CVl4SAUaUQ
> "FLCN" "FLCN" "FLCN"
> "UCA1" "IL1B"
>
> Thanks
> Ana

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] how to REPLACE VALUES in a dataframe

2012-02-05 Thread Valerie Moore
Hi,

I have two data frames (u and v).

 u
  coe  nam
1   0 Time
2   0    Poten
3   0   AdvExp
4   0    Share
5   0   Change
6   0 Accounts
7   0 Work
8   0   Rating


 v
  coeff    enter
1 0.7272727 Accounts
2 0.322 Time
3 0.0500123    Poten


I want to update the values of coe in u by using the values ofcoeff in v.
That is, I want to get the following result

 u
  coe               nam
1   0.322 Time
2   0.0500123    Poten
3   0               AdvExp
4   0               Share
5   0               Change
6    0.7272727   Accounts
7   0       Work
8   0   Rating


OR the following result is also acceptable:

0.322    0.0500123    0    0    0 0.7272727    0    0


I tried the following, but the result is not right.
replace(coe,colnames,coeff)
[1] 0.7272727 0.0500123 0.322 0.000 0.000 0.000 0.000
[8] 0.000


PLEASE HELP ME. 

THANK YOU VERY MUCH.




~valerie
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to REPLACE VALUES in a dataframe

2012-02-05 Thread Jim Holtman
indx - match(u$nam, v$enter, nomatch = 0)
u$coe[indx != 0] - v$coeff[indx]

Sent from my iPad

On Feb 5, 2012, at 15:45, Valerie Moore vmoore2...@yahoo.com wrote:

 Hi,
 
 I have two data frames (u and v).
 
 u
   coe  nam
 1   0 Time
 2   0Poten
 3   0   AdvExp
 4   0Share
 5   0   Change
 6   0 Accounts
 7   0 Work
 8   0   Rating
 
 
 v
   coeffenter
 1 0.7272727 Accounts
 2 0.322 Time
 3 0.0500123Poten
 
 
 I want to update the values of coe in u by using the values ofcoeff in v.
 That is, I want to get the following result
 
 u
   coe   nam
 1   0.322 Time
 2   0.0500123Poten
 3   0   AdvExp
 4   0   Share
 5   0   Change
 60.7272727   Accounts
 7   0   Work
 8   0   Rating
 
 
 OR the following result is also acceptable:
 
 0.3220.0500123000 0.727272700
 
 
 I tried the following, but the result is not right.
 replace(coe,colnames,coeff)
 [1] 0.7272727 0.0500123 0.322 0.000 0.000 0.000 0.000
 [8] 0.000
 
 
 PLEASE HELP ME. 
 
 THANK YOU VERY MUCH.
 
 
 
 
 ~valerie
[[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] _: how to replace values in x by means in subgroups created in ...(not loops)

2011-07-28 Thread Eugeniusz Kałuża
, ()
#and it does perfectly the problem that I proposed.

#2. Could we ask for a little modification in that code,
#to make it more general,
#more generaal, i.e. to do it working when y starts from 1 y=c(1,...

 x-1:(50*1000)
 y-c(1,sample(c(0,1), length(x)-1, replace = TRUE)  )

#-


#-
# next to try in looking for faster solutions mayby:
#require(sqldf)
# centered moving average of length 7
#set.seed(1)
#DF - data.frame(x = rnorm(15, 1:15))
#s18 - sqldf(select a.x x, avg(b.x) movavgx from DF a, DF b
#   where a.row_names - b.row_names between -3 and 3
#   group by a.row_names having count(*) = 7
#   order by a.row_names+0,
# row.names = TRUE)
#r18 - data.frame(x = DF[4:12,], movavgx = rowMeans(embed(DF$x, 7)))
#row.names(r18) - NULL
#all.equal(r18, s18)
#-






 
#_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_#

-Wiadomo¶æ oryginalna-
Od: ONKELINX, Thierry [mailto:thierry.onkel...@inbo.be]
Wys³ano: ¦r 2011-07-27 11:36
Do: Eugeniusz Ka³u¿a; r-help@r-project.org
Temat: RE: how to replace values in x by means in subgroups created in ...(not 
loops)
 
Something like this?

dataset - data.frame(x = x, y = y)
dataset$Group - cumsum(c(0, diff(!is.na(dataset$y)  dataset$y == 0)) == 1)
library(plyr)
tmp - ddply(subset(dataset, y == 0), .(Group), function(z){c(Mean = mean(z$x, 
na.rm = TRUE))})
result - merge(dataset, tmp)
result$Mean[is.na(result$y) | result$y != 0] - result$x[is.na(result$y) | 
result$y != 0]

Best regards,

Thierry

 -Oorspronkelijk bericht-
 Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 Namens Eugeniusz Kaluza
 Verzonden: woensdag 27 juli 2011 11:21
 Aan: r-help@r-project.org
 Onderwerp: [R] how to replace values in x by means in subgroups created in 
 ...
 (not loops)
 
 
 # Dear all,
 # how to replace values in x by means in subgroups created in ...
 # replace only these values where y=0 in continous sequence # replace by mean
 calculated locally for each subgroup created by # continous sequence of 
 0,0,0 in
 parallel y vector, i.e.
 # where there is continous sequence of 0 in data frame vector y
 #but we do not replace values in x[i], if y[i]!=0
 # we do not want use loops we do not use apply (not very fast)
 
 
 x  -c(0 ,1,2,3,4,5,6,7,8,NA,NA,1  ,1 ,NA,2  ,2)
 y  -c(0 ,0,0,1,0,0,0,1,1,1 ,NA,0  ,0 ,0 ,0  ,1)
 Must_be-c(1 ,1,1,3,5,5,5,7,8,NA,NA,1.5,1 ,NA,1.5,2)
 
 (df-as.data.frame(cbind(x,y))  )
 
 # I have traied many bad colusions based on cumsum, pmin, pmax, ...
 (mean_dfx_if_yIs0-y*cumsum(x*y)/(cumsum(y)*y) )
 
 # how to do this?
 # thans for any advice
 # E


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] how to replace values in x by means in subgroups created in ... (not loops)

2011-07-27 Thread Eugeniusz Kałuża

# Dear all,
# how to replace values in x by means in subgroups created in ...
# replace only these values where y=0 in continous sequence
# replace by mean calculated locally for each subgroup created by 
# continous sequence of 0,0,0 in parallel y vector, i.e. 
# where there is continous sequence of 0 in data frame vector y 
#but we do not replace values in x[i], if y[i]!=0 
# we do not want use loops we do not use apply (not very fast) 


x  -c(0 ,1,2,3,4,5,6,7,8,NA,NA,1  ,1 ,NA,2  ,2)
y  -c(0 ,0,0,1,0,0,0,1,1,1 ,NA,0  ,0 ,0 ,0  ,1)
Must_be-c(1 ,1,1,3,5,5,5,7,8,NA,NA,1.5,1 ,NA,1.5,2)

(df-as.data.frame(cbind(x,y))  )

# I have traied many bad colusions based on cumsum, pmin, pmax, ... 
(mean_dfx_if_yIs0-y*cumsum(x*y)/(cumsum(y)*y) )

# how to do this?
# thans for any advice 
# E

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to replace values in x by means in subgroups created in ... (not loops)

2011-07-27 Thread ONKELINX, Thierry
Something like this?

dataset - data.frame(x = x, y = y)
dataset$Group - cumsum(c(0, diff(!is.na(dataset$y)  dataset$y == 0)) == 1)
library(plyr)
tmp - ddply(subset(dataset, y == 0), .(Group), function(z){c(Mean = mean(z$x, 
na.rm = TRUE))})
result - merge(dataset, tmp)
result$Mean[is.na(result$y) | result$y != 0] - result$x[is.na(result$y) | 
result$y != 0]

Best regards,

Thierry

 -Oorspronkelijk bericht-
 Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
 Namens Eugeniusz Kaluza
 Verzonden: woensdag 27 juli 2011 11:21
 Aan: r-help@r-project.org
 Onderwerp: [R] how to replace values in x by means in subgroups created in ...
 (not loops)
 
 
 # Dear all,
 # how to replace values in x by means in subgroups created in ...
 # replace only these values where y=0 in continous sequence # replace by mean
 calculated locally for each subgroup created by # continous sequence of 0,0,0 
 in
 parallel y vector, i.e.
 # where there is continous sequence of 0 in data frame vector y
 #but we do not replace values in x[i], if y[i]!=0
 # we do not want use loops we do not use apply (not very fast)
 
 
 x  -c(0 ,1,2,3,4,5,6,7,8,NA,NA,1  ,1 ,NA,2  ,2)
 y  -c(0 ,0,0,1,0,0,0,1,1,1 ,NA,0  ,0 ,0 ,0  ,1)
 Must_be-c(1 ,1,1,3,5,5,5,7,8,NA,NA,1.5,1 ,NA,1.5,2)
 
 (df-as.data.frame(cbind(x,y))  )
 
 # I have traied many bad colusions based on cumsum, pmin, pmax, ...
 (mean_dfx_if_yIs0-y*cumsum(x*y)/(cumsum(y)*y) )
 
 # how to do this?
 # thans for any advice
 # E
 
   [[alternative HTML version deleted]]
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How to replace values?

2009-04-30 Thread Suhaila Zainudin
Hello all,

I have a list of genes as follows (A)

Number  GeneName
0 YAR003W
1 YAR007C
2 YAR008W
3 YBL035C
4 YBL111C
5 YBL112C

And I have a list of gene interactions as follows (B)

0 - 1
1 - 5
3 - 4
2 - 3

I want to replace the values in (B) with the corresponding values in
(A) ie, I want to achieve the following

0 - 1 replaced with YAR003W -YAR007C
1 - 5 replaced with YAR007C - YBL112C
3 - 4 replaced with YBL035C -   YBL111C
2 - 3 replaced with YAR008W - YBL035C

The example is simple with (A) and (B) only having a few lines.  But
in reality, (A) may contain more than 1000 genes and (B) may contain
thousands of interactions.

Any suggestions  on how to achieve the above task are welcomed!



--
Suhaila Zainudin
PhD Candidate
Universiti Teknologi Malaysia

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to replace values?

2009-04-30 Thread Sigbert Klinke
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Hi,

If the coding would start at 1 rather than 0 then +1's in the
penultimate line could be eliminated.

Sigbert

- ---

gene - c(YAR003W, YAR007C, YAR008W, YBL035C, YBL111C, YBL112C)
print(gene)
to   - c(0,1,3,2) # to   - c(1,2,4,3)
from - c(1,5,4,3) # from - c(2,6,5,4)
gene[to+1] - gene[from+1] # gene[to] - gene[from]
print(gene)
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD4DBQFJ+YKUWvYUYQkj1zkRAjlVAJ9NrHySXnFCUmyBS7XbBwgAeOu1XQCVHvCa
omPs62LERNyQJ/+I9uL52g==
=seex
-END PGP SIGNATURE-

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.