How to extract information from .Rdata format

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

How to extract information from .Rdata format

anikaM
Hello,

I have this file:
> a=load("paired_example.Rdata")
> a
[1] "rawdata"   "treatment" "patient"

I can extract "rawdata" with:
 dat<-local(get(load("paired_example.Rdata")))

Can you please advise how would I extract in data frame "treatment"
and "patient"?

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 extract information from .Rdata format

Bert Gunter-2
What does
str(a)

give?


Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Jul 31, 2020 at 7:18 PM Ana Marija <[hidden email]>
wrote:

> Hello,
>
> I have this file:
> > a=load("paired_example.Rdata")
> > a
> [1] "rawdata"   "treatment" "patient"
>
> I can extract "rawdata" with:
>  dat<-local(get(load("paired_example.Rdata")))
>
> Can you please advise how would I extract in data frame "treatment"
> and "patient"?
>
> 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[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 extract information from .Rdata format

Sarah Goslee
In reply to this post by anikaM
Hi Ana,

You are making this far too complicated.

load("paired_example.Rdata")

ls()

str(rawdata)
str(treatment)
str(patient)

load() puts all of them into your current environment. If you assign
the result of load() to something, in your example a, that object
contains the names of the objects, but the objects themselves are in
your workspace.

You should probably try a basic R tutorial; it will help you with this
kind of thing.

Sarah

On Fri, Jul 31, 2020 at 10:18 PM Ana Marija <[hidden email]> wrote:

>
> Hello,
>
> I have this file:
> > a=load("paired_example.Rdata")
> > a
> [1] "rawdata"   "treatment" "patient"
>
> I can extract "rawdata" with:
>  dat<-local(get(load("paired_example.Rdata")))
>
> Can you please advise how would I extract in data frame "treatment"
> and "patient"?
>
> 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.



--
Sarah Goslee (she/her)
http://www.numberwright.com

______________________________________________
[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 extract information from .Rdata format

anikaM
In reply to this post by anikaM
Hi Bert,

it gives me this:

> a=load("paired_example.Rdata")
> str(a)
 chr [1:3] "rawdata" "treatment" "patient"

I don't know how to extract "treatment" for example in a data frame.

I tried this but of no help.
> b=a[[2]]
> b
[1] "treatment"

> str(treatment)
 chr [1:10] "treat" "treat" "treat" "treat" "treat" "control" "control" ...

but this is not the format I need.

On Fri, Jul 31, 2020 at 9:18 PM Ana Marija <[hidden email]> wrote:

>
> Hello,
>
> I have this file:
> > a=load("paired_example.Rdata")
> > a
> [1] "rawdata"   "treatment" "patient"
>
> I can extract "rawdata" with:
>  dat<-local(get(load("paired_example.Rdata")))
>
> Can you please advise how would I extract in data frame "treatment"
> and "patient"?
>
> 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 extract information from .Rdata format

anikaM
It seems that "treatment" and "patient" are just vectors.

> treatment
 [1] "treat"   "treat"   "treat"   "treat"   "treat"   "control" "control"
 [8] "control" "control" "control"
> patient
 [1] "a" "b" "c" "d" "e" "a" "b" "c" "d" "e"

On Fri, Jul 31, 2020 at 9:53 PM Ana Marija <[hidden email]> wrote:

>
> Hi Bert,
>
> it gives me this:
>
> > a=load("paired_example.Rdata")
> > str(a)
>  chr [1:3] "rawdata" "treatment" "patient"
>
> I don't know how to extract "treatment" for example in a data frame.
>
> I tried this but of no help.
> > b=a[[2]]
> > b
> [1] "treatment"
>
> > str(treatment)
>  chr [1:10] "treat" "treat" "treat" "treat" "treat" "control" "control" ...
>
> but this is not the format I need.
>
> On Fri, Jul 31, 2020 at 9:18 PM Ana Marija <[hidden email]> wrote:
> >
> > Hello,
> >
> > I have this file:
> > > a=load("paired_example.Rdata")
> > > a
> > [1] "rawdata"   "treatment" "patient"
> >
> > I can extract "rawdata" with:
> >  dat<-local(get(load("paired_example.Rdata")))
> >
> > Can you please advise how would I extract in data frame "treatment"
> > and "patient"?
> >
> > 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 extract information from .Rdata format

Bert Gunter-2
In reply to this post by anikaM
Sarah has explained all.

I agree with her about the need for tutorials also. This list cannot
substitute for such homework on your own.

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Jul 31, 2020 at 7:55 PM Ana Marija <[hidden email]>
wrote:

> Hi Bert,
>
> it gives me this:
>
> > a=load("paired_example.Rdata")
> > str(a)
>  chr [1:3] "rawdata" "treatment" "patient"
>
> I don't know how to extract "treatment" for example in a data frame.
>
> I tried this but of no help.
> > b=a[[2]]
> > b
> [1] "treatment"
>
> > str(treatment)
>  chr [1:10] "treat" "treat" "treat" "treat" "treat" "control" "control" ...
>
> but this is not the format I need.
>
> On Fri, Jul 31, 2020 at 9:18 PM Ana Marija <[hidden email]>
> wrote:
> >
> > Hello,
> >
> > I have this file:
> > > a=load("paired_example.Rdata")
> > > a
> > [1] "rawdata"   "treatment" "patient"
> >
> > I can extract "rawdata" with:
> >  dat<-local(get(load("paired_example.Rdata")))
> >
> > Can you please advise how would I extract in data frame "treatment"
> > and "patient"?
> >
> > 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[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 extract information from .Rdata format

anikaM
do you think that this is useful output from Basics of R?
> load("paired_example.Rdata")
> str(rawdata)
 num [1:4482, 1:10] 46 4 3 48 1 4 0 60 0 12 ...
 - attr(*, "dimnames")=List of 2
  ..$ : chr [1:4482] "gene1" "gene2" "gene3" "gene4" ...
  ..$ : chr [1:10] "a.cancer" "b.cancer" "c.cancer" "d.cancer" ..

I think this one is better:
> dat<-local(get(load("paired_example.Rdata")))
> head(dat)
      a.cancer b.cancer c.cancer d.cancer e.cancer a.normal b.normal c.normal
gene1       46        4       33        5        8       61        5       42
gene2        4        0        2        1        5       24        1       30
gene3        3        4        4        2        1        3        0        0
gene4       48        2       10        0        6        9        4        3
gene5        1        5        2        3        6        1        0        3
gene6        4        0        0        1        1        4        0        7

On Fri, Jul 31, 2020 at 11:05 PM Bert Gunter <[hidden email]> wrote:

>
> Sarah has explained all.
>
> I agree with her about the need for tutorials also. This list cannot substitute for such homework on your own.
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Fri, Jul 31, 2020 at 7:55 PM Ana Marija <[hidden email]> wrote:
>>
>> Hi Bert,
>>
>> it gives me this:
>>
>> > a=load("paired_example.Rdata")
>> > str(a)
>>  chr [1:3] "rawdata" "treatment" "patient"
>>
>> I don't know how to extract "treatment" for example in a data frame.
>>
>> I tried this but of no help.
>> > b=a[[2]]
>> > b
>> [1] "treatment"
>>
>> > str(treatment)
>>  chr [1:10] "treat" "treat" "treat" "treat" "treat" "control" "control" ...
>>
>> but this is not the format I need.
>>
>> On Fri, Jul 31, 2020 at 9:18 PM Ana Marija <[hidden email]> wrote:
>> >
>> > Hello,
>> >
>> > I have this file:
>> > > a=load("paired_example.Rdata")
>> > > a
>> > [1] "rawdata"   "treatment" "patient"
>> >
>> > I can extract "rawdata" with:
>> >  dat<-local(get(load("paired_example.Rdata")))
>> >
>> > Can you please advise how would I extract in data frame "treatment"
>> > and "patient"?
>> >
>> > 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 extract information from .Rdata format

Rui Barradas
Hello,

Inline.

Às 05:30 de 01/08/2020, Ana Marija escreveu:
> do you think that this is useful output from Basics of R?

Actually, the answer will be yes, I do. Explanation follows.

>> load("paired_example.Rdata")
>> str(rawdata)
>   num [1:4482, 1:10] 46 4 3 48 1 4 0 60 0 12 ...
>   - attr(*, "dimnames")=List of 2
>    ..$ : chr [1:4482] "gene1" "gene2" "gene3" "gene4" ...
>    ..$ : chr [1:10] "a.cancer" "b.cancer" "c.cancer" "d.cancer" ..

This says that rawdata is a numeric matrix with 4482 rows and 10 columns.
And that an useful attribute, dimnames, is set.

>
> I think this one is better:
>> dat<-local(get(load("paired_example.Rdata")))
>> head(dat)
>        a.cancer b.cancer c.cancer d.cancer e.cancer a.normal b.normal c.normal
> gene1       46        4       33        5        8       61        5       42
> gene2        4        0        2        1        5       24        1       30
> gene3        3        4        4        2        1        3        0        0
> gene4       48        2       10        0        6        9        4        3
> gene5        1        5        2        3        6        1        0        3
> gene6        4        0        0        1        1        4        0        7

This gives a better *visual* representation of the data, rawdata is an
object of class "matrix" and it now *looks* like a table. We are used to
seeing matrices printed like this so it's very easy to understand what
rawdata is about.
Note that this one only has 8 columns, did you process the data before
calling head()?

Anyway, why not run both str(rawdata) and head(rawdata)? Not only I
don't see a conflict, they are even complementary to one another.

As for the original question, Sarah did answer to it, when you load() a
.Rdata or .RData file the objects are created in a certain environment
and their names are returned, you don't need get(), it's redundant.

Hope this helps,

Rui Barradas

>
> On Fri, Jul 31, 2020 at 11:05 PM Bert Gunter <[hidden email]> wrote:
>> Sarah has explained all.
>>
>> I agree with her about the need for tutorials also. This list cannot substitute for such homework on your own.
>>
>> Bert Gunter
>>
>> "The trouble with having an open mind is that people keep coming along and sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>>
>> On Fri, Jul 31, 2020 at 7:55 PM Ana Marija <[hidden email]> wrote:
>>> Hi Bert,
>>>
>>> it gives me this:
>>>
>>>> a=load("paired_example.Rdata")
>>>> str(a)
>>>   chr [1:3] "rawdata" "treatment" "patient"
>>>
>>> I don't know how to extract "treatment" for example in a data frame.
>>>
>>> I tried this but of no help.
>>>> b=a[[2]]
>>>> b
>>> [1] "treatment"
>>>
>>>> str(treatment)
>>>   chr [1:10] "treat" "treat" "treat" "treat" "treat" "control" "control" ...
>>>
>>> but this is not the format I need.
>>>
>>> On Fri, Jul 31, 2020 at 9:18 PM Ana Marija <[hidden email]> wrote:
>>>> Hello,
>>>>
>>>> I have this file:
>>>>> a=load("paired_example.Rdata")
>>>>> a
>>>> [1] "rawdata"   "treatment" "patient"
>>>>
>>>> I can extract "rawdata" with:
>>>>   dat<-local(get(load("paired_example.Rdata")))
>>>>
>>>> Can you please advise how would I extract in data frame "treatment"
>>>> and "patient"?
>>>>
>>>> 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.


--
Este e-mail foi verificado em termos de vírus pelo software antivírus Avast.
https://www.avast.com/antivirus

______________________________________________
[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.