[R] How to create a data set from object/data frame?
Sarah Goslee
@@r@h@go@|ee @end|ng |rom gm@||@com
Fri Jul 19 20:25:25 CEST 2019
Okay, at this point I have three suggestions, because you're clearly
not yet understanding the R workflow.
1. Read at least the Intro to R manual.
https://cran.r-project.org/doc/manuals/R-intro.pdf
2. Go through your sample code carefully, step by step, using
functions like str() and head() to look at the R objects produced at
each step, using ? to investigate functions you aren't familiar with,
and thinking as you go how those R objects do and don't resemble the
data you have.
3. If 1 and 2 don't help, you need to consult with your advisor,
mentor, or if there's nobody local to you that can help, the author of
the sample code you're using.
I don't have your sample code, don't have your data, am not familiar
with the specific functions you are using, and don't have time to
become familiar. You need to both improve your R understanding and
seek out guidance, ideally from someone whose job it is to help you.
Best,
Sarah
On Fri, Jul 19, 2019 at 1:47 PM Spencer Brackett
<spbrackett20 using saintjosephhs.com> wrote:
>
> Okay. I am a little confused as to how to proceed with that. The next part of the procedure as seen below appears to be substituting information from this fake data set into the following arguments in order to
>
> sample.info <- data.frame( + spl=paste('A', 1:8, sep=''), + stat=rep(c('cancer' , 'healthy'), each=4))
>
> ##Then a meta data.frame object was created to give more intelligible labels##
>
> > meta.info <- data.frame (labelDescription = + c('Sample Name' , 'Cancer Status')) Then we put them all together: > pheno <- new("AnnotatedDataFrame", + data = sample.info, + varMetadata = meta.info)
>
> ##Which was then aggregated together##
>
> > pheno <- new("AnnotatedDataFrame", + data = sample.info, + varMetadata = meta.info)
>
> >my.experiments <- new("ExpressionSet", + exprs=fake.data, phenoData=pheno)
> > my.experiments
> ExpressionSet (storageMode: lockedEnvironment) assayData: 200 features, 8 samples element names: exprs
>
> ##The following deals with further manipulating the phenoData##
> phenoData
> sampleNames: 1, 2, ..., 8 (8 total) varLabels and varMetadata description: spl: Sample Name stat: Cancer Status
>
> featureData
> featureNames: 1, 2, ..., 200 (200 total)
> fvarLabels and fvarMetadata description: none
> experimentData: use 'experimentData(object)'
> Annotation:
>
> ##At this point is when the dataset 'Dilution' was read in through data(Dilution)
>
> >library(affydata)
> > data(Dilution)
>
> which was made an object of the AnnotatedDataFrame via
> >Dilution
> >phenoData(Dilution)
> >pData(Dilution)
>
> ##To access the probesets###
>
> > geneNames(Dilution)[1:3] [1] "100_g_at" "1000_at" "1001_at"
> > random.affyid <- sample(geneNames(Dilution), 1)
> > # random.affyid <- '34803_at'
> > ps <- probeset(Dilution, random.affyid)[[1]]
>
> How would I substitute in my anno object to achieve this?
>
>
>
>
> On Fri, Jul 19, 2019 at 1:32 PM Sarah Goslee <sarah.goslee using gmail.com> wrote:
>>
>> You don't need fake.data or rnorm(), which was used to generate the fake data.
>>
>> You need to use your real data for the analysis, not anything randomly
>> generated for example purposes, or anything included with a package
>> for example purposes.
>>
>> In both cases, those are just worked examples.You need to analyze your
>> own comparable data.
>>
>> Sarah
>>
>> On Fri, Jul 19, 2019 at 12:17 PM Spencer Brackett
>> <spbrackett20 using saintjosephhs.com> wrote:
>> >
>> > Sarah,
>> >
>> > Thank you for the reference to ?data. Upon further research into the matter, I think I can provide a simpler explanation than the one previously provided. I am trying to reproduce the following code with an object -- 'anno' -- in my data frame/environment.
>> >
>> > >fake.data <- matrix(rnorm(8*200), ncol=8)
>> >
>> > I found the number of columns with >ncol(anno) , which is 3
>> >
>> > How do I find rnorm when I don't have the data table (saved as the 'anno' object) mean or standard dev. ?
>> >
>> > I will try reading in the data object through read.table() now, though won't that just print the data or a subset thereof into my R console?
>> >
>> >
>> >
>> > On Fri, Jul 19, 2019 at 10:46 AM Spencer Brackett <spbrackett20 using saintjosephhs.com> wrote:
>> >>
>> >> Sarah,
>> >>
>> >> I am trying to extract phenoData (ie sample information) from the object as part of a procedure to analyze my array for probe sets, which I realize is under the BioConducter package Biobase and not relevant to this mailing list.
>> >>
>> >> Yes the original procedure uses data from the Dilution dataset hosted in the AffyBatch package affydata. Previous to this part of the procedure, a dataset was create via..
>> >>
>> >> >fake.data <- matrix(rnorm(8*200), ncol=8)
>> >> ##Then phenotype (sample) data was generated in this example through... ##
>> >>
>> >> sample.info <- data.frame( + spl=paste('A', 1:8, sep=''), + stat=rep(c('cancer' , 'healthy'), each=4))
>> >>
>> >> ##Then a meta data.frame object was created to give more intelligible labels##
>> >>
>> >> > meta.info <- data.frame (labelDescription = + c('Sample Name' , 'Cancer Status')) Then we put them all together: > pheno <- new("AnnotatedDataFrame", + data = sample.info, + varMetadata = meta.info)
>> >>
>> >> ##Which was then aggregated together##
>> >>
>> >> > pheno <- new("AnnotatedDataFrame", + data = sample.info, + varMetadata = meta.info)
>> >>
>> >> >my.experiments <- new("ExpressionSet", + exprs=fake.data, phenoData=pheno)
>> >> > my.experiments
>> >> ExpressionSet (storageMode: lockedEnvironment) assayData: 200 features, 8 samples element names: exprs
>> >>
>> >> ##The following deals with further manipulating the phenoData##
>> >> phenoData
>> >> sampleNames: 1, 2, ..., 8 (8 total) varLabels and varMetadata description: spl: Sample Name stat: Cancer Status
>> >>
>> >> featureData
>> >> featureNames: 1, 2, ..., 200 (200 total) fvarLabels and fvarMetadata description: none
>> >> experimentData: use 'experimentData(object)'
>> >> Annotation:
>> >>
>> >> ##At this point is when the dataset 'Dilution was read in through data(Dilution)
>> >>
>> >> which was made an object of the AnnotatedDataFrame via
>> >>
>> >> >phenoData(Dilution)
>> >>
>> >> My apologies in advance as I know the above info. pertains to functions carried out strictly through BioConducor, but is the only context I can provide for what I am trying to do.
>> >>
>> >> Best,
>> >>
>> >> Spencer
>> >>
>> >>
>> >> On Fri, Jul 19, 2019 at 10:23 AM Sarah Goslee <sarah.goslee using gmail.com> wrote:
>> >>>
>> >>> Hi Spencer,
>> >>>
>> >>> Your description doesn't make any sense to me. If anno is already an R
>> >>> object, what are you trying to do with it?
>> >>>
>> >>> data() is for loading datasets that come with packages; if your object
>> >>> is already an R object in your environment, then there's no need for
>> >>> it.
>> >>>
>> >>> It sounds like you are possibly working through an example provided
>> >>> elsewhere, that has sample data loaded with data(). If so, then you do
>> >>> not need that step for your own data. You just need to import it into
>> >>> R in the correct format.
>> >>>
>> >>> If that doesn't help, then I think we need more information on what
>> >>> you're trying to do.
>> >>>
>> >>> Sarah
>> >>>
>> >>> On Fri, Jul 19, 2019 at 10:18 AM Spencer Brackett
>> >>> <spbrackett20 using saintjosephhs.com> wrote:
>> >>> >
>> >>> > Hello,
>> >>> >
>> >>> > I am trying to create a data set from an object called ‘anno’ in my
>> >>> > environment. I’ve tried arguments like saveRDS(anno, file = “”) and
>> >>> > save(anno, file “.RData”) to save the object as a file to see if that will
>> >>> > work, but it seems for the particular procedure I am trying to carry out, I
>> >>> > need to transpose the object to a data set. Any ideas as to how I might do
>> >>> > this? For reference, my next step in manipulating the data contained in the
>> >>> > object is data(), which evidently does not work for reading in data frame
>> >>> > objects as data(“file/object name).
>> >>> >
>> >>> > Best,
>> >>> >
>> >>> > Spencer
>> >>> >\
--
Sarah Goslee (she/her)
http://www.numberwright.com
More information about the R-help
mailing list