Re: [R] Subsetting Data from a Dataframe

2019-05-24 Thread Rui Barradas
Hello, Maybe something like the following is what you want. The code first creates a logical index of columns with at least one NA or "NULL" (character string, not NULL) values. Then extracts only those columns from the dataframe. inx <- sapply(datos, function(x) any(x == "NULL" | is.na(x)))

Re: [R] Subsetting Data from a Dataframe

2019-05-24 Thread Sarah Goslee
Hi Paul, Thanks for the reproducible data. You really only need to provide enough to illustrate your question, but this works. I suspect you have a data import problem - I doubt you really want so many columns to be factors! Probably you need to specify that NULL means something specific, rather

Re: [R] Subsetting data with svyglm

2015-02-11 Thread Anthony Damico
hi brennan, survey design objects can be subsetted with the same subset() syntax as data.frame objects, so following jeff's advice maybe you want svyglm( formula , design = subset( surveydesign , variable %in% c( 'value a' , 'value b' ) ) ) for some examples of how to construct a survey design wi

Re: [R] Subsetting data with svyglm

2015-02-11 Thread Jeff Newmiller
This seems like a fundamental misunderstanding on your part of how operators, and in particular logical expressions, work in computer languages. Consider some examples: 1+2 has a numeric answer because 1 and 2 are both numeric. 1+"a" has at the very least not a numeric answer because the values

Re: [R] Subsetting data for split-sample validation, then repeating 1000x

2014-08-22 Thread David L Carlson
values. hist(Out) # for a histogram of the correlation values David C From: Angela Boag [mailto:angela.b...@colorado.edu] Sent: Friday, August 22, 2014 4:01 PM To: David L Carlson Subject: Re: [R] Subsetting data for split-sample validation, then repeating 1000x Hi David, Thanks for the f

Re: [R] Subsetting data for split-sample validation, then repeating 1000x

2014-08-22 Thread David L Carlson
You can use replicate() or a for (i in 1:1000){} loop to do your replications, but you have other issues first. 1. You are sampling with replacement which makes no sense at all. Your 70% sample will contain some observations multiple times and will use less than 70% of the data most of the tim

Re: [R] subsetting data file by intoducing a second file

2013-02-12 Thread Eik Vettorazzi
Hi Ozgul, the interesting part is the "select" parameter in subset: subset(bg,select=c_bg[,1]) cheers Am 12.02.2013 15:29, schrieb Ozgul Inceoglu: > Hello, > > I have a very data matrix and I have a file which has the names that I need > to subset. However I cannot manage to subset the main f

Re: [R] subsetting data file by intoducing a second file

2013-02-12 Thread arun
Hi, bg<- read.table(text=" Otu00022 Otu00029 Otu00039 Otu00042 Otu00101 Otu00105 Otu00125 Otu00131 Otu00137 Otu00155 Otu00158 Otu00172 Otu00181 Otu00185 Otu00190 Otu00209 Otu00218 Gi20Jun11  0.001217    0 0.001217    0 0.00    0    0    0 0.001217    0    0 

Re: [R] subsetting data file by intoducing a second file

2013-02-12 Thread Rui Barradas
Hello, Read the help page ?subset more carefully, it's argument 'select' you should be using: subset(bg, select = c_bg) Hope this helps, Rui Barradas Em 12-02-2013 14:29, Ozgul Inceoglu escreveu: Hello, I have a very data matrix and I have a file which has the names that I need to subse

Re: [R] Subsetting data leads to funky plots

2011-11-12 Thread Sarah Goslee
Hi, On Sat, Nov 12, 2011 at 2:04 AM, Vinny Moriarty wrote: > I'm trying out a basic plot, but something about the way I subset my data > leads to problems with the plot. > > > Here is the first bit of my data set > > year,date,location,quadrat_juvenile,photo_location,photo_exists,genus,count,dive

Re: [R] Subsetting data by eliminating redundant variables

2011-10-19 Thread R. Michael Weylandt
Assuming you are talking about redun() from the Hmisc package, it's much easier than you are making it: n <- 100 x1 <- runif(n) x2 <- runif(n) x3 <- x1 + x2 + runif(n)/10 x4 <- x1 + x2 + x3 + runif(n)/10 x5 <- factor(sample(c('a','b','c'),n,replace=TRUE)) x6 <- 1*(x5=='a' | x5=='c') data1 <- data.

Re: [R] Subsetting data systematically

2011-06-24 Thread gibberish
Thanks! From: Peter Alspach-2 [via R] [mailto:ml-node+3618799-1094957657-247...@n4.nabble.com] Sent: Wednesday, June 22, 2011 9:27 PM To: Bendik, Nathan Subject: Re: Subsetting data systematically Tena ko

Re: [R] Subsetting data systematically

2011-06-22 Thread Peter Alspach
Tena koe Nate You can use the fact that R recycles. If yourData is a dataframe, then (as examples): yourData[c(TRUE,FALSE),] will give you every second row, starting with the first. Similarly, yourData[c(FALSE,TRUE,FALSE),] will give every third row, starting with the second; and yourData[c(

Re: [R] Subsetting Data

2011-04-28 Thread David Winsemius
On Apr 28, 2011, at 3:38 PM, David Winsemius wrote: On Apr 28, 2011, at 3:13 PM, Abraham Mathew wrote: I'm using the subset() function in R. dat <- data.frame(one=c(6,7,8,9,10), Number=c(5,15,13,1,13)) subset(dat, Number >= 10) However, I want to find the number of all rows who meet the

Re: [R] Subsetting Data

2011-04-28 Thread David Winsemius
On Apr 28, 2011, at 3:13 PM, Abraham Mathew wrote: I'm using the subset() function in R. dat <- data.frame(one=c(6,7,8,9,10), Number=c(5,15,13,1,13)) subset(dat, Number >= 10) However, I want to find the number of all rows who meet the Number>=10 condition. I've done this in the past with s

Re: [R] Subsetting Data

2011-04-28 Thread Jonathan Daily
Try this: sum(dat$Number >= 10) On Thu, Apr 28, 2011 at 3:13 PM, Abraham Mathew wrote: > I'm using the subset() function in R. > > dat <- data.frame(one=c(6,7,8,9,10), Number=c(5,15,13,1,13)) > > subset(dat, Number >= 10) > > However, I want to find the number of all rows who meet the Number>=10

Re: [R] subsetting data by specified observation number

2011-03-05 Thread Greg Snow
Here is one way: > tmp1 <- data.frame(Species=c('setosa','virginica','versicolor'), + row=c(7,20,18) ) > > tmp.iris <- iris > tmp.iris$row <- ave(iris$Sepal.Length, iris$Species, FUN=seq_along) > > out.iris <- merge(tmp.iris, tmp1, by=c('Species','row')) > > > out.iris Species row Sepal.L

Re: [R] subsetting data by specified observation number

2011-03-05 Thread Linh Tran
Hi, Thank you for the reply. That would only work for the first ID. In addition, the data frame that I'm trying to subset is separate from the data frame that has the position numbers. "failed.3" is the data frame with the position numbers that I would like to keep. "def3" is the data frame that

Re: [R] subsetting data by specified observation number

2011-03-05 Thread Greg Snow
Will failed.3 have each id exactly once? Or could it have multiple lines for a given id? -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-

Re: [R] subsetting data by specified observation number

2011-03-05 Thread jdnew...@gmail.com
What is wrong with subset( failed.3, position == 2 ) ? -- Sent from my Android phone with K-9 Mail. Please excuse my brevity. Linh Tran wrote: Hi members, I'd like to thank you guys ahead of time for the help. I'm kind of stuck. I have a data frame with ID and position numbers: 1> head(faile

Re: [R] subsetting data points within confidence limit

2010-08-13 Thread Greg Snow
Why would you want to do this? Confidence intervals tell you about the uncertainty of the mean of y give x, not the individual data points. It may make more sense to use prediction intervals that tell you about individuals rather than means, but that still means throwing away alpha% of legitim

Re: [R] Subsetting Data Frame based On Specified K Value

2009-09-03 Thread Bill.Venables
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 321 0.67 1 65

Re: [R] subsetting data frame using a vector of column names / values

2009-06-24 Thread Blazej Krzeminski
This "one liner" works great! Thanks (for all replies) > > Try this: > > subset(d, eval(parse(text = paste(paste(columns, values, sep = "=="), > collapse = " & " > >> >> Hello >> >> I have a data frame d with columns "var1", "var2", "var3" >> >> Then I have two vectors: >> columns <- c("var2

Re: [R] subsetting data frame using a vector of column names / values

2009-06-24 Thread Henrique Dallazuanna
Try this: subset(d, eval(parse(text = paste(paste(columns, values, sep = "=="), collapse = " & " On Wed, Jun 24, 2009 at 9:16 AM, Blazej Krzeminski wrote: > Hello > > I have a data frame d with columns "var1", "var2", "var3" > > Then I have two vectors: > columns <- c("var2", "var3") > valu

Re: [R] Subsetting data where the condition is that the value of some column contains some substring

2009-03-20 Thread Max Bane
Aha, I get it now. I was under the mistaken, intuitive impression that the subset condition was evaluated element-by-element... I guess it must actually work out to a vector of booleans, each element of which gets compared to the corresponding element of the data to be subsetted. That is, in hindsi

Re: [R] Subsetting data where the condition is that the value of some column contains some substring

2009-03-20 Thread David Winsemius
If you use Jim's example and use grep() with ordinary and and then negative indexing, you get these results: > x[grep("her", x$input),] input output corpusFreq pvolOT pvolRatioOT 2 donate(her,thebook) P 48.7 68928 0.1899471 6give(her,it) P 100.0 1

Re: [R] Subsetting data where the condition is that the value of some column contains some substring

2009-03-20 Thread jim holtman
grep and regexpr return different values. regexpr returns a vector of the same length as the input and this can be used to construct a logical subscript. grep return a vector of only the matches, in which case you can have a length of zero if there are no matches. Makes it harder to create the s

Re: [R] Subsetting data where the condition is that the value of some column contains some substring

2009-03-20 Thread Max Bane
Thanks, Jim (and Mark, who replied off-list) -- that does the trick. I had tried using an index expression with grep, but that failed in the same way as the subset method. It is still rather mysterious why this works with regexpr but not with grep :) -Max On Fri, Mar 20, 2009 at 7:57 PM, jim holt

Re: [R] Subsetting data where the condition is that the value of some column contains some substring

2009-03-20 Thread jim holtman
Try using regexpr instead: > x <- read.table(textConnection("input output corpusFreq pvolOT pvolRatioOT + give(mysister,theoldbook) P 47.0 56016 0.1543651 + donate(her,thebook) P 48.7 68928 0.1899471 + give(mysister,thebook) P 73.4 80136 0.2208333 + donate

Re: [R] Subsetting data in a loop

2008-10-29 Thread hadley wickham
?split. Hadley On Wed, Oct 29, 2008 at 3:22 PM, t c <[EMAIL PROTECTED]> wrote: > I need some help with sub-setting my data. I am trying to divide a data > frame into multiple data frames based on the year collected, and stored in a > list with each new data frame labeled with "year X" where X

Re: [R] Subsetting data by date

2008-07-21 Thread Gabor Grothendieck
26 PM > To: Williams, Robin > Cc: R-help@r-project.org > Subject: Re: [R] Subsetting data by date > > Continuing on, to just get points from May to Sep > > mo <- as.numeric(format(time(z), "%m")) > z.summer <- z[mo >= 5 & mo <= 9] > > If in your case

Re: [R] Subsetting data by date

2008-07-21 Thread John Kane
?subset is one of several ways. You don't need a loop. Loops are BAD in R :) --- On Mon, 7/21/08, Williams, Robin <[EMAIL PROTECTED]> wrote: > From: Williams, Robin <[EMAIL PROTECTED]> > Subject: Re: [R] Subsetting data by date > To: "Gabor Grothendieck"

Re: [R] Subsetting data by date

2008-07-21 Thread John Kane
PM > To: Williams, Robin > Cc: R-help@r-project.org > Subject: Re: [R] Subsetting data by date > > Continuing on, to just get points from May to Sep > > mo <- as.numeric(format(time(z), "%m")) > z.summer <- z[mo >= 5 & mo <= 9] > > If in your case

Re: [R] Subsetting data by date

2008-07-21 Thread Williams, Robin
] -Original Message- From: Gabor Grothendieck [mailto:[EMAIL PROTECTED] Sent: Monday, July 21, 2008 3:26 PM To: Williams, Robin Cc: R-help@r-project.org Subject: Re: [R] Subsetting data by date Continuing on, to just get points from May to Sep mo <- as.numeric(format(time(z),

Re: [R] Subsetting data by date

2008-07-21 Thread Williams, Robin
Forecasting [EMAIL PROTECTED] -Original Message- From: Gabor Grothendieck [mailto:[EMAIL PROTECTED] Sent: Monday, July 21, 2008 3:26 PM To: Williams, Robin Cc: R-help@r-project.org Subject: Re: [R] Subsetting data by date Continuing on, to just get points from May to Sep mo <- as.nume

Re: [R] Subsetting data by date

2008-07-21 Thread Gabor Grothendieck
Continuing on, to just get points from May to Sep mo <- as.numeric(format(time(z), "%m")) z.summer <- z[mo >= 5 & mo <= 9] If in your case z is multivariate rather than univariate (as it is in our example) then it would be: z.summer <- z[mo >= 5 & mo <= 9, ] On Mon, Jul 21, 2008 at 9:55 AM, Gabo

Re: [R] Subsetting data by date

2008-07-21 Thread Gabor Grothendieck
Try this: Lines <- "Date,Temp 1-Apr-1997,50 3-Sept-2001,60" library(zoo) # function to reduce 4 char mos to 3 char convert.date <- function(x, format) as.Date(sub("(-...).-", "\\1-", x), format) # z <- read.zoo("myfile.csv", header = TRUE, sep = ",", FUN = convert.date, format = "%d-%b-%Y") z <

Re: [R] subsetting data-frame by vector of characters

2008-06-13 Thread Wacek Kusnierczyk
james perkins wrote: > Thanks a lot for that. Its the %in% I needed to work out mainly > > large didn't mean anything in particular, just that it gets quite long > with the real data. > I did mean: names = c("John", "Phil", "Robert") > > The only problem is that using the method you suggest is that

Re: [R] subsetting data-frame by vector of characters

2008-06-13 Thread Peter Dalgaard
james perkins wrote: > Thanks a lot for that. Its the %in% I needed to work out mainly > > large didn't mean anything in particular, just that it gets quite long > with the real data. > I did mean: names = c("John", "Phil", "Robert") > > The only problem is that using the method you suggest is that

Re: [R] subsetting data-frame by vector of characters

2008-06-13 Thread james perkins
Thanks a lot for that. Its the %in% I needed to work out mainly large didn't mean anything in particular, just that it gets quite long with the real data. I did mean: names = c("John", "Phil", "Robert") The only problem is that using the method you suggest is that I lose the indexing, ie in t

Re: [R] subsetting data-frame by vector of characters

2008-06-13 Thread Wacek Kusnierczyk
james perkins wrote: > Hi, > > I have a very simple problem but I can't think how to solve it without > using a for loop and creating a large logical vector. However given > the nature of the problem I am sure there is a "1-liner" that could do > the same thing much more efficiently. > > bascially

Re: [R] subsetting data-frame by vector of characters

2008-06-13 Thread Chuck Cleland
On 6/13/2008 10:07 AM, james perkins wrote: Hi, I have a very simple problem but I can't think how to solve it without using a for loop and creating a large logical vector. However given the nature of the problem I am sure there is a "1-liner" that could do the same thing much more efficientl

Re: [R] Subsetting data frame problem....

2008-01-01 Thread Simon Blomberg
Or use complete.cases df.complete <- df[complete.cases(df),] Simon. On Wed, 2008-01-02 at 13:21 +1000, Ross Darnell wrote: > You could try > > > > complete.case.df <- na.omit(df) > > > Ross Darnell > > > -Original Message- > From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] > On B

Re: [R] Subsetting data frame problem....

2008-01-01 Thread Ross Darnell
You could try > complete.case.df <- na.omit(df) Ross Darnell -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Marko Milicic Sent: Wednesday, 2 January 2008 11:50 AM To: r-help@r-project.org Subject: [R] Subsetting data frame problem Dear R users,

Re: [R] Subsetting data frame problem....

2008-01-01 Thread jim holtman
?complete.cases On Jan 1, 2008 8:50 PM, Marko Milicic <[EMAIL PROTECTED]> wrote: > Dear R users, > > I'm new but already fascinated R user so please forgive for my > ignorance. I have the problem, I read most of help pages but couldn't > find the solution. The problem follows > > I have large