Gundala Viswanath
2009-Sep-03 06:44 UTC
[R] Subsetting Data Frame based On Specified K Value
I have a data that looks like this: http://dpaste.com/88988/plain/ How can I extract/subset the data frame based on selected uniq ID. Let's say I want the first K uniq ID. I want to be able to specify the parameter "K" here, (i.e. given K=3, we hope to extract dat$V2 = 0,1,2). I'm stuck with this construct: dat <- read.table("http://dpaste.com/88988/plain/") dats <- subset(dat, V2 = ....) - G.V.
Bill.Venables at csiro.au
2009-Sep-03 07:16 UTC
[R] Subsetting Data Frame based On Specified K Value
Is this what you want?> dat <- read.table("http://dpaste.com/88988/plain/",comment.char="", header = TRUE)> names(dat)[1] "X.ID" "VALUE" "FREQUENCY"> subset(dat, X.ID %in% 0:2 & !duplicated(X.ID))X.ID VALUE FREQUENCY 1 0 0.00 3 32 1 0.67 1 65 2 1.70 1 Bill Venables http://www.cmis.csiro.au/bill.venables/ -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Gundala Viswanath Sent: Thursday, 3 September 2009 4:44 PM To: r-help at stat.math.ethz.ch Subject: [R] Subsetting Data Frame based On Specified K Value I have a data that looks like this: http://dpaste.com/88988/plain/ How can I extract/subset the data frame based on selected uniq ID. Let's say I want the first K uniq ID. I want to be able to specify the parameter "K" here, (i.e. given K=3, we hope to extract dat$V2 = 0,1,2). I'm stuck with this construct: dat <- read.table("http://dpaste.com/88988/plain/") dats <- subset(dat, V2 = ....) - G.V. ______________________________________________ R-help at r-project.org mailing list 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.
Apparently Analagous Threads
- How to plot two cumulative frequency graph together
- Howto Superimpose Multiple Density Curves Into One Plot
- Create Matrix from Loop of Vectors, Sort It and Pick Top-K
- image works in native but not in vm when cpu mode='host-passthrough' is set
- Measuring Goodness of a Matrix