[R] How to extract data based on first column ID in R

David Winsemius dw|n@em|u@ @end|ng |rom comc@@t@net
Sun Jun 23 22:38:40 CEST 2019


> On Jun 23, 2019, at 5:57 AM, Yogesh Gupta <nabiyogesh using gmail.com> wrote:
> 
> Hi,
> 
> I need help to extract data based on first column ID in R.
> 
> I used the below code but not succeed , it is not giving the row values,
> only showing the header of rows.
> 
>> head(data)
> 
> 
> Root-1.S35.L001.    Root-10.S75.L001
> 
> 71f84e7910006f22684121564206e8ca      0.00000000                0

A more accurate method of presenting R objects would be to offer the output of:

dput(head(data))

But working with this I have the hypothesis that your first column is numeric while the character values listed along the left side of that output are the rownames which cannot be accessed with the "[[" operator.

So your code might have been:

i <- rownames(data) %in% otu.list
dim(i)


> 
> 03b167b9f86f2519b4263b4125377eed      0.00000000                0
> 
> 54e204fb99c80764e964456dadd6a0e5      0.00000000                0
> 
> 55cd1fc570879d645bbf7a3642e9b0a8      0.00000000                0
> 
> 65f5c31e12c277aec319e2096463f9d2      0.00000000                0
> 
> 7bed62f0fef250fd831dcf13bf43f4fc           0.04679457                0
> 
> 
> .....................................................
> 
> 
>> head(otu.list)
> 
>  9d94ce7d60e59034941e3a12bc37865e
> 
> 1 8e60d301122d7aa359eb6b0b00f37f62
> 
> 2 bfad6370d28182cc6304844e9bec7fb6
> 
> 3 088571139af8e0a63fb6652df8a7438b
> 
> 4 ccd70d57890f276a542ef4b5e5142d4c
> 
> 5 cab4ca278af34bf722e0c7cb3219370b
> 
> 6 72f30f3780145f16ac882eb8e2d189a5
> 
> 
> ....................................
> 
> 
>> i <- data[[1]] %in% otu.list
> 
>> dim(i)
> 
> NULL
> 
>> data[i, ]
> 
> [1] Root-1.S35.L001  Root-10.S75.L001 Root-13.S5.L001  Root-14.S16.L001
> 
> [5] Root-17.S26.L001 Root-18.S36.L001 Root-19.S46.L001 Root-22.S56.L001
> 
> [9] Root-24.S66.L001 Root-25.S76.L001 Root-26.S6.L001  Root-27.S17.L001
> 
> [13] Root-3.S45.L001  Root-30.S27.L001 Root-32.S37.L001 Root-34.S47.L001
> 
> [17] Root-39.S57.L001 Root-4.S55.L001  Root-40.S67.L001 Root-41.S77.L001
> 
> [21] Root-43.S7.L001  Root-45.S18.L001 Root-47.S28.L001 Root-50.S38.L001
> 
> 
> .............
> 
> 
> Could you please suggest how I can get the row values along with the header?
> 
> 
> Thanks
> 
> Yogesh
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help using 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.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'   -Gehm's Corollary to Clarke's Third Law



More information about the R-help mailing list