[R] remove quotes from matrix

greg holly mak.hholly at gmail.com
Tue Sep 19 17:38:41 CEST 2017


Hi Bert;

I sincerely appreciate for this. When I follow your way I have got
dimnames(dm)
[[1]]
NULL

I think this is the reason why the matrix is being converted into  a column
vector.

Regards,

Greg

On Tue, Sep 19, 2017 at 11:32 AM, Bert Gunter <bgunter.4567 at gmail.com>
wrote:

> Works fine for me. What do you object to in the following?
>
> Calling the above df "d",
>
> > dm <- as.matrix(d)
> > dm
>   Sub_Pathways            BMI_beta   SAT_beta   VAT_beta
> 1 "Alanine_and_Aspartate" " 0.23820" "-0.02409" " 0.94180"
> 2 "Alanine_and_Aspartate" "-0.31300" "-1.97510" "-2.22040"
> 3 "Alanine_and_Aspartate" " 0.12380" " 0.40950" " 0.68050"
> 4 "Alanine_and_Aspartate" " 0.30350" " 0.48610" " 0.70830"
> 5 "Alanine_and_Aspartate" "-0.00982" " 0.32930" " 0.01597"
>   VSR_beta
> 1 " 0.24690"
> 2 "-0.23540"
> 3 " 0.05539"
> 4 " 0.01337"
> 5 "-0.04353"
> > dimnames(dm)
> [[1]]
> [1] "1" "2" "3" "4" "5"
>
> [[2]]
> [1] "Sub_Pathways" "BMI_beta"     "SAT_beta"     "VAT_beta"
> [5] "VSR_beta"
>
> > dm <- noquote(dm)
> > dm
>   Sub_Pathways          BMI_beta SAT_beta VAT_beta VSR_beta
> 1 Alanine_and_Aspartate  0.23820 -0.02409  0.94180  0.24690
> 2 Alanine_and_Aspartate -0.31300 -1.97510 -2.22040 -0.23540
> 3 Alanine_and_Aspartate  0.12380  0.40950  0.68050  0.05539
> 4 Alanine_and_Aspartate  0.30350  0.48610  0.70830  0.01337
> 5 Alanine_and_Aspartate -0.00982  0.32930  0.01597 -0.04353
> > dimnames(dm)
> [[1]]
> [1] "1" "2" "3" "4" "5"
>
> [[2]]
> [1] "Sub_Pathways" "BMI_beta"     "SAT_beta"     "VAT_beta"
> [5] "VSR_beta"
>
>
> Perhaps you need to read ?noquote or ?matrix.
>
> -- Bert
>
>
>
> 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 Tue, Sep 19, 2017 at 8:20 AM, greg holly <mak.hholly at gmail.com> wrote:
>
>> Dear all;
>>
>> Thanks. Here are the dput results as Duncan suggested.
>>
>> Regards,
>>
>> Greg
>>
>> structure(list(Sub_Pathways = structure(c(3L, 3L, 3L, 3L, 3L), .Label =
>> c("Acetylated_Peptides",
>> "Advanced_Glycation_End-product", "Alanine_and_Aspartate", "Aminosugar",
>> "Ascorbate_and_Aldarate", "Carnitine", "Ceramides", "Creatine",
>> "Diacylglycerol", "Dipeptide", "Dipeptide_Derivative",
>> "Disaccharides_and_Oligosaccharides",
>> "Eicosanoid", "Endocannabinoid", "Fatty_Acid(Acyl_Carnitine)",
>> "Fatty_Acid(Acyl_Glycine)", "Fatty_Acid,_Amino", "Fatty_Acid,_Branched",
>> "Fatty_Acid,_Dicarboxylate", "Fatty_Acid,_Dihydroxy",
>> "Fatty_Acid,_Monohydroxy",
>> "Fatty_Acid_(Acyl_Choline)", "Fatty_Acid_(Acyl_Glutamine)",
>> "Fatty_Acid_(also_BCAA)",
>> "Fatty_Acid_Synthesis", "Fibrinogen_Cleavage_Peptide",
>> "Fructose,_Mannose_and_Galactose",
>> "Gamma-glutamyl_Amino_Acid", "Glutamate", "Glutathione", "Glycerolipid",
>> "Glycine,_Serine_and_Threonine", "Glycogen",
>> "Glycolysis,_Gluconeogenesis,_and_Pyruvate",
>> "Guanidino_and_Acetamido", "Hemoglobin_and_Porphyrin", "Histidine",
>> "Inositol", "Ketone_Bodies", "Leucine,_Isoleucine_and_Valine",
>> "Long_Chain_Fatty_Acid", "Lysine", "Lyso-phospho-ether", "Lysolipid",
>> "Lysoplasmalogen", "Medium_Chain_Fatty_Acid",
>> "Methionine,_Cysteine,_SAM_and_Taurine",
>> "Mevalonate", "Monoacylglycerol", "Nicotinate_and_Nicotinamide",
>> "Oxidative_Phosphorylation", "Pantothenate_and_CoA", "Pentose",
>> "Phenylalanine_and_Tyrosine", "Phospholipid", "Plasmalogen",
>> "Polyamine", "Polypeptide", "Polyunsaturated_Fatty_Acid_(n3_and_n6)",
>> "Primary_Bile_Acid", "Purine,_(Hypo)Xanthine/Inosine_containing",
>> "Purine,_Adenine_containing", "Purine,_Guanine_containing",
>> "Pyrimidine,_Cytidine_containing",
>> "Pyrimidine,_Orotate_containing", "Pyrimidine,_Thymine_containing",
>> "Pyrimidine,_Uracil_containing", "Riboflavin", "Secondary_Bile_Acid",
>> "Short_Chain_Fatty_Acid", "Sphingolipid", "Steroid", "Sterol",
>> "TCA_Cycle", "Tocopherol", "Tryptophan",
>> "Urea_cycle;_Arginine_and_Proline",
>> "Vitamin_A", "Vitamin_B6"), class = "factor"), BMI_beta = c(0.2382,
>> -0.313, 0.1238, 0.3035, -0.00982), SAT_beta = c(-0.02409, -1.9751,
>> 0.4095, 0.4861, 0.3293), VAT_beta = c(0.9418, -2.2204, 0.6805,
>> 0.7083, 0.01597), VSR_beta = c(0.2469, -0.2354, 0.05539, 0.01337,
>> -0.04353)), .Names = c("Sub_Pathways", "BMI_beta", "SAT_beta",
>> "VAT_beta", "VSR_beta"), row.names = c(NA, 5L), class = "data.frame")
>>
>> On Tue, Sep 19, 2017 at 10:04 AM, Duncan Murdoch <
>> murdoch.duncan at gmail.com>
>> wrote:
>>
>> > On 19/09/2017 9:47 AM, greg holly wrote:
>> >
>> >> Hi all;
>> >>
>> >> I have data at 734*22 dimensions with rows and columns names are
>> >> non-numeric.When I convert this data into matrix then all values show
>> up
>> >> with quotes. Then when I use
>> >> x1= noquotes(x) to remove the quotes from the matrix then non-numeric
>> row
>> >> names remain all other values in matrix disappear.
>> >>
>> >> Your help is greatly appreciated.
>> >>
>> >>
>> >
>> > Matrices in R can have only one type.  If you start with a dataframe and
>> > any columns contain character data, all entries will be converted to
>> > character, and the matrix will be displayed with quotes.
>> >
>> > When you say all values disappear, it sounds as though you are
>> displaying
>> > strings containing nothing (or just blanks).  Those will be displayed
>> as ""
>> > normally, but if the matrix is marked to display without quotes, they
>> are
>> > displayed as empty strings, so it will appear that nothing is displayed.
>> >
>> > You can see the structure of the original data using the str() function,
>> > e.g. str(x) should display types for each column.
>> >
>> > If this isn't enough to explain what's going on, please show us more
>> > detail.  For example, show us the result of
>> >
>> > y <- x[1:5, 1:5]
>> > dput(y)
>> >
>> > both before and after converting x to a matrix.
>> >
>> > Duncan Murdoch
>> >
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at 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/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list