how to replace values in a named vector

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

how to replace values in a named vector

anikaM
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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: how to replace values in a named vector

anikaM
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 <[hidden email]> 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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

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

Richard M. Heiberger
I can't understand non-words with that many letters.  I think this is what you
are looking for:

> tmp <- c(A="a",B="b",C="c",D="d")
> names(tmp)
[1] "A" "B" "C" "D"
> tmp
  A   B   C   D
"a" "b" "c" "d"
> ## change values of B and C to "x" and "y"
> names(tmp) %in% c("B","C")
[1] FALSE  TRUE  TRUE FALSE
> tmp[names(tmp) %in% c("B","C")]
  B   C
"b" "c"
> tmp[names(tmp) %in% c("B","C")] <- c("x","y")
> tmp
  A   B   C   D
"a" "x" "y" "d"
>

If not, please ask the question again with simpler-appearing vectors and show
us what you would like the answer to be.

On Mon, Sep 14, 2020 at 12:37 PM Ana Marija <[hidden email]> wrote:

>
> 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 <[hidden email]> 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
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: how to replace values in a named vector

Rui Barradas
In reply to this post by anikaM
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 <[hidden email]> 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
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.