Re: [R] $ subset operator behavior in lapply

2022-10-28 Thread Hilmar Berger
Hi Andrew, thanks a lot, that fully explains it. Sorry for the HTML text. For the record I put the original code again below. Best regards Hilmar On 27.10.22 18:34, Andrew Simmons wrote: > $ does not evaluate its second argument, it does something like > as.character(substitute(name)). > > Yo

Re: [R] $ subset operator behavior in lapply

2022-10-27 Thread Jeff Newmiller
Your message is garbled. Please send plain text to the mailing list. On October 27, 2022 2:31:47 AM PDT, Hilmar Berger wrote: >Dear all, > >I'm a little bit surprised by the behavior of the $ operator when used >in lapply - any indication what might be wrong is appreciated. > >> xx = list(A=list(

Re: [R] $ subset operator behavior in lapply

2022-10-27 Thread Andrew Simmons
$ does not evaluate its second argument, it does something like as.character(substitute(name)). You should be using lapply(list, function(x) x$a) or lapply(list, `[[`, "a") On Thu, Oct 27, 2022, 12:29 Hilmar Berger wrote: > Dear all, > > I'm a little bit surprised by the behavior of the $ o

Re: [R] subset data frame problem

2021-12-13 Thread Kai Yang via R-help
Thans Richard, it works well. --- Kai On Monday, December 13, 2021, 04:00:33 AM PST, Richard O'Keefe wrote: You want to DELETE rows satisfying the condition P & Q.The subset() function requires an expression saying whatyou want to RETAIN, so you need subset(PD, !(P & Q)). test <- subs

Re: [R] subset data frame problem

2021-12-13 Thread Richard O'Keefe
You want to DELETE rows satisfying the condition P & Q. The subset() function requires an expression saying what you want to RETAIN, so you need subset(PD, !(P & Q)). test <- subset(PD, !(Class == "1st" & Survived == "No")) By de Morgan's laws, !(P & Q) is the same as (!P) | (!Q) so you could als

Re: [R] subset data frame problem

2021-12-12 Thread Jeff Newmiller
Use one ampersand, not two. And post plain text. On December 12, 2021 8:30:11 PM PST, Kai Yang via R-help wrote: >Hi R team,I want to delete records from a data frame if Class = '1st' and >Survived = 'No'. I wrote the code below, test <- subset(PD, Class != '1st' && >Survived != 'No') >but th

Re: [R] Subset command

2021-10-15 Thread Bert Gunter
I assume that prim, etc. are columns of your data frame, mydata. Ergo, the error message "prim not found" as 'prim' etc. does not exist in the Global environment. exclude <- with(mydata, prim == -9, etc. ) should get what you want to evaluate your second subset statement if I have understood corre

Re: [R] Subset command

2021-10-15 Thread Steven Yen
Thanks. YES the second call to subset is there, trying to use my failed definition of "exclude". Read on.. On 2021/10/16 上午 09:35, Jeff Newmiller wrote: I don't see a "second one". Looks like you forgot the subset function call? On October 15, 2021 6:23:56 PM PDT, Steven Yen wrote: The follo

Re: [R] Subset command

2021-10-15 Thread Jeff Newmiller
I don't see a "second one". Looks like you forgot the subset function call? On October 15, 2021 6:23:56 PM PDT, Steven Yen wrote: >The following "subset command works. I was hoping the second would as >well but it does not. > >My definition of exclude is rejected. > >Help please? Thanks. > > > m

Re: [R] Subset a data frame with specific date

2020-01-14 Thread PIKAL Petr
-Original Message- > From: R-help On Behalf Of Bert Gunter > Sent: Tuesday, January 14, 2020 8:10 AM > To: ani jaya > Cc: r-help > Subject: Re: [R] Subset a data frame with specific date > > That's fine, but do note that the which() function is wholly unnecessary in

Re: [R] Subset a data frame with specific date

2020-01-13 Thread ani jaya
Thank you Bert. And yes another topic to study. On Tue, Jan 14, 2020 at 4:10 PM Bert Gunter wrote: > > That's fine, but do note that the which() function is wholly unnecessary in > your last line as R allows logical indexing. Perhaps another topic you need > to study. > > -- Bert > > > > On Mon

Re: [R] Subset a data frame with specific date

2020-01-13 Thread Bert Gunter
That's fine, but do note that the which() function is wholly unnecessary in your last line as R allows logical indexing. Perhaps another topic you need to study. -- Bert On Mon, Jan 13, 2020 at 10:56 PM ani jaya wrote: > Dear Jeff and Bert, > > Thank you very much for your correction and expl

Re: [R] Subset a data frame with specific date

2020-01-13 Thread ani jaya
Dear Jeff and Bert, Thank you for your correction and explanation. Yes, I need more study regarding date format and sorry for HTML mail. I was able to subset data that I want. mjo30<-read.table("rmm.txt", header=FALSE, skip=4234, nrows=10957) mjo30$V8<-NULL names(mjo30)<-c("year","month","day",

Re: [R] Subset a data frame with specific date

2020-01-13 Thread ani jaya
Dear Jeff and Bert, Thank you very much for your correction and explanation. And yes, I need to study about date format more. Sorry for HTML mail, don't realize. I was able to subset the data that I want. mjo30<-read.table("rmm.txt", header=FALSE, skip=4234, nrows=10957) mjo30$V8<-NULL names(mjo

Re: [R] Subset a data frame with specific date

2020-01-13 Thread Bert Gunter
Inline. Bert Gunter On Mon, Jan 13, 2020 at 8:54 PM ani jaya wrote: > Good morning R-Help, > > I have a dataframe with 7 columns and 1+ rows. I want to subset/extract > those data frame with specific date (not in order). Here the head of my > data frame: > > head(mjo30) > year month d

Re: [R] Subset a data frame with specific date

2020-01-13 Thread Jeff Newmiller
The dput function is for re-creating an R object in another R workspace, so it uses fundamental base types to define objects. A Date is really the number of days since a specific date (typically 1970-01-01) that get converted to look like dates whenever you display or print them, so what you are

Re: [R] subset English language using textcat package

2018-11-19 Thread Robert David Burbidge via R-help
Look at the help docs and examples for textcat and sapply: print(as.character(data$x[sapply(data$x, textcat)=="english"])) Although textcat defaults classify "This book is amazing" as dutch, so you may want to read the help for textcat and change the profile db ("p") or "method". On 19/11/20

Re: [R] subset only if f.e a column is successive for more than 3 values

2018-09-28 Thread William Dunlap via R-help
Do you also want lines 38 and 39 (in addition to 40:44), or do I misunderstand your problem? When you deal with runs of data, think of the rle (run-length encoding) function. E.g. here is a barely tested function to find runs of a given minimum length and a given difference between successive val

Re: [R] subset only if f.e a column is successive for more than 3 values

2018-09-28 Thread Knut Krueger
Hi Jim, thank's it is working with the given example, but whats the difference when using testdata=data.frame(TIME=c("17:11:20", "17:11:21", "17:11:22", "17:11:23", "17:11:24", "17:11:25", "17:11:26", "17:11:27", "17:11:28", "17:21:43", "17:22:16", "17:22:19", "18:04:48"

Re: [R] subset only if f.e a column is successive for more than 3 values

2018-09-27 Thread Jim Lemon
Bugger! It's eval(parse(text=paste0("kkdf[c(",paste(starts,ends,sep=":",collapse=","),"),]"))) What a mess! Jim On Fri, Sep 28, 2018 at 8:35 AM Jim Lemon wrote: > > Hi Knut, > As Bert said, you can start with diff and work from there. I can > easily get the text for the subset, but despite fool

Re: [R] subset only if f.e a column is successive for more than 3 values

2018-09-27 Thread Jim Lemon
Hi Knut, As Bert said, you can start with diff and work from there. I can easily get the text for the subset, but despite fooling around with "parse", "eval" and "expression", I couldn't get it to work: # use a bigger subset to test whether multiple runs can be extracted kkdf<-subset(airquality,Te

Re: [R] subset only if f.e a column is successive for more than 3 values

2018-09-27 Thread Bert Gunter
1. I assume the values are integers, not floats/numerics (which woud make it more complicated). 2. Strategy: Take differences (e.g. see ?diff) and look for >3 1's in a row. I don't have time to work out details, but perhaps that helps. Cheers, Bert Bert Gunter "The trouble with having an open

Re: [R] Subset Rasterbrick by time

2018-06-19 Thread Miluji Sb
Dear David, Subsetting works but the 'date' information is lost in the new file. Thanks, Mike. I was not aware of the bug but will work on learning about (getZ) and (setZ). Thanks again! Sincerely, Milu On Tue, Jun 19, 2018 at 7:32 AM, Michael Sumner wrote: > > > On Mon, 18 Jun 2018, 22:09 D

Re: [R] Subset Rasterbrick by time

2018-06-18 Thread Michael Sumner
On Mon, 18 Jun 2018, 22:09 David Winsemius, wrote: > > > > On Jun 18, 2018, at 7:21 AM, Miluji Sb wrote: > > > > Dear all, > > > > I have a rasterbrick with the date/time information provided which I > would > > like to subset by year. > > > > However, when I use the following code for sub-setti

Re: [R] Subset Rasterbrick by time

2018-06-18 Thread David Winsemius
> On Jun 18, 2018, at 7:21 AM, Miluji Sb wrote: > > Dear all, > > I have a rasterbrick with the date/time information provided which I would > like to subset by year. > > However, when I use the following code for sub-setting; > > new_brick <- subset(original, which(getZ( original ) >= as.D

Re: [R] Subset

2017-09-25 Thread Bert Gunter
You realize, do you not, that in fact there are no numbers in your "list" (actually a vector). It looks like you would do well to spend some time with an R tutorial or two before posting further to this list. We can help, but cannot substitute for the basic knowledge that you would gain from doin

Re: [R] Subset

2017-09-25 Thread Shane Carey
Super, thanks Boris. Top notch :-) On Mon, Sep 25, 2017 at 1:05 PM, Boris Steipe wrote: > Always via logical expressions. In this case you can use the logical > expression > > myDF$b != "0" > > to give you a vector of TRUE/FALSE > > > > B. > > > > On Sep 25, 2017, at 8:00 AM, Shane Carey wrote

Re: [R] Subset

2017-09-25 Thread Boris Steipe
Always via logical expressions. In this case you can use the logical expression myDF$b != "0" to give you a vector of TRUE/FALSE B. > On Sep 25, 2017, at 8:00 AM, Shane Carey wrote: > > This is super, really helpfull. Sorry, one final question, lets say I wanted > to remove 0's rather t

Re: [R] Subset

2017-09-25 Thread Shane Carey
This is super, really helpfull. Sorry, one final question, lets say I wanted to remove 0's rather than NAs , what would it be? Thanks On Mon, Sep 25, 2017 at 12:41 PM, Boris Steipe wrote: > myDF <- data.frame(a = c("<0.1", NA, 0.3, 5, "Nil"), >b = c("<0.1", 1, 0.3, 5, "Nil")

Re: [R] Subset

2017-09-25 Thread Boris Steipe
myDF <- data.frame(a = c("<0.1", NA, 0.3, 5, "Nil"), b = c("<0.1", 1, 0.3, 5, "Nil"), stringsAsFactors = FALSE) # you can subset the b-column in several ways myDF[ , 2] myDF[ , "b"] myDF$b # using the column, you make a logical vector ! is.na(as.numeric(myDF

Re: [R] Subset

2017-09-25 Thread Shane Carey
Hi, Lets say this was a dataframe where I had two columns a <- c("<0.1", NA, 0.3, 5, "Nil") b <- c("<0.1", 1, 0.3, 5, "Nil") And I just want to remove the rows from the dataframe where there were NAs in the b column, what is the syntax for doing that? Thanks in advance On Fri, Sep 22, 2017 at

Re: [R] Subset

2017-09-22 Thread Shane Carey
Super, Thanks On Fri, Sep 22, 2017 at 4:57 PM, Boris Steipe wrote: > > a <- c("<0.1", NA, 0.3, 5, "Nil") > > a > [1] "<0.1" NA "0.3" "5""Nil" > > > b <- as.numeric(a) > Warning message: > NAs introduced by coercion > > b > [1] NA NA 0.3 5.0 NA > > > b[! is.na(b)] > [1] 0.3 5.0 > > >

Re: [R] Subset

2017-09-22 Thread Boris Steipe
> a <- c("<0.1", NA, 0.3, 5, "Nil") > a [1] "<0.1" NA "0.3" "5""Nil" > b <- as.numeric(a) Warning message: NAs introduced by coercion > b [1] NA NA 0.3 5.0 NA > b[! is.na(b)] [1] 0.3 5.0 B. > On Sep 22, 2017, at 11:48 AM, Shane Carey wrote: > > Hi, > > How do I extract just n

Re: [R] Subset()

2017-01-21 Thread Jim Lemon
Hi Elise, One of the quirks of POSIXt time values is that they are lists. This should give you the plot: plot(Soil_Temp~as.numeric(DateTime),eldf,xaxt="n",xlab="DateTime") and this the x axis: axis.POSIXct(1,eldf$DateTime) If you want a different format for the date values on the axis, look at

Re: [R] Subset()

2017-01-21 Thread Jim Lemon
Hi Elise, If I create a CSV file like your example and read it into a data frame: eldf<-read.csv("el.csv") Then convert the first field to POSIXt dates: eldf$DateTime<-strptime(eldf$DateTime,"%Y-%m-%d %H:%M:%S") class(eldf$DateTime) [1] "POSIXlt" "POSIXt" I can subset the file like this: time_

Re: [R] Subset()

2017-01-21 Thread Jim Lemon
Hi Elise,. I would ask: class(data$DateTime) and see if it returns: "POSIXct" "POSIXt" Jim On Sat, Jan 21, 2017 at 3:02 AM, Elise LIKILIKI wrote: > Hello, > > I have a dataset containing Date Time, Air Temperature, PPFD, Sol > Temperature... > The first data are false so I would like to extr

Re: [R] Subset()

2017-01-20 Thread David Winsemius
How are we supposed to help you if you don’t read the Posting Guide and don’t provide any information about the classes of columns in `data`.? — David. > On Jan 20, 2017, at 10:02 AM, Elise LIKILIKI wrote: > > Hello, > > I have a dataset containing Date Time, Air Temperature, PPFD, Sol > Te

Re: [R] Subset and sumerize

2016-10-14 Thread Mark Sharp
Ashta, ## I may have misunderstood your question and if so I apologize. ## I had to remove the extra line after "45" before ## the ",sep=" to use your code. ## You could have used dput(dat) to send a more reliable (robust) version. dat <- structure(list(ID = c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L,

Re: [R] Subset and sumerize

2016-10-14 Thread Sarah Goslee
For the data you provide, it's simply: summary(subset(dat, x1 == "x" & x2 == "z")$y) Note that x1 and x2 are factors in your example. We also don't know what you want to do if there are more than one combination of that per ID, or if there ID values with no matching rows. Sarah On Fri, Oct 14,

Re: [R] subset data right

2016-05-27 Thread William Dunlap via R-help
>If you want to drop levels, use droplevels() either on the factor or on the >subset of your data frame. Example: >droplevels(f[1]) #One element, only one level Calling factor() on a factor, as the OP did, also drops any unused levels, as the examples showed. > str(factor(factor(letters)[11:13]))

Re: [R] subset data right

2016-05-27 Thread S Ellison
> You did not change df$quant - you made a new object called 'subdf' > containing a column called 'quant' that had only one level. Changing subdf > has > no effect on df. Also, subsetting a factor _intentionally_ does not change the number of levels. Example: f <- factor(sample(letters[1:3], 30

Re: [R] subset data right

2016-05-26 Thread William Dunlap via R-help
You did not change df$quant - you made a new object called 'subdf' containing a column called 'quant' that had only one level. Changing subdf has no effect on df. > df <- data.frame(quant=factor(letters)) > str(df) 'data.frame': 26 obs. of 1 variable: $ quant: Factor w/ 26 levels "a","b","c",

Re: [R] subset data right

2016-05-26 Thread ruipbarradas
Hello, Don't use subset, use indexing. subdf <- df[df$quant %in% "VeryFast", ] By the way, instead of %in% you can use ==, since you're interested in just one value of quant. Hope this helps, Rui Barradas Citando ch.elahe via R-help : > Hi all, > I have the following df and I want to know

Re: [R] subset by multiple letters condition

2016-04-23 Thread Adams, Jean
This is quite a different question. I suggest you start a new post with a new subject line for this. And I suggest you include code for an example plot that you want to use. Otherwise, you might look here for some ideas on how to control colors in a scatter plot using base r, http://stackoverflo

Re: [R] subset by multiple letters condition

2016-04-23 Thread ch.elahe via R-help
Thanks Jean, Does anyone know how to set these [hast1] and [hast2] as the colors of a plot? On Friday, April 22, 2016 7:39 AM, "Adams, Jean" wrote: You can use the grepl() function to give you logicals for each criterion, then combine them as needed. For example: # example version of Co

Re: [R] subset by multiple letters condition

2016-04-22 Thread Adams, Jean
You can use the grepl() function to give you logicals for each criterion, then combine them as needed. For example: # example version of Command Command <- paste0("_localize_", c("PD","t2","t1_seq", "abc", "xyz", "PD_t1")) hasPD <- grepl("PD", Command, fixed=TRUE) hast1 <- grepl("t1", Command, f

Re: [R] subset by multiple letters condition

2016-04-22 Thread Giorgio Garziano
You may investigate a solution based on regular expressions. Some tutorials to help: http://www.regular-expressions.info/rlanguage.html http://www.endmemo.com/program/R/grep.php http://biostat.mc.vanderbilt.edu/wiki/pub/Main/SvetlanaEdenRFiles/regExprTalk.pdf https://rstudio-pubs-static.s3.ama

Re: [R] Subset with missing argument within a function

2016-02-05 Thread William Dunlap via R-help
R's subscripting operators do not "guess" the value of a missing argument: a missing k'th subscript means seq_len(dim(x)[k]). I bet that you use syntax like x[,1] (the entire first column of x) all the time and that you don't want this syntax to go away. Some languages use a placeholder like '.' o

Re: [R] Subset with missing argument within a function

2016-02-04 Thread Stefano de Pretis
Thanks Bill, This is more clear. In any case, I find very inappropriate that a programming language tries to guess the value of a missing argument. It is unfair towards code developers and it promotes the production of bugged piece of software. I hope R will revise its policies sooner or later.

Re: [R] Subset with missing argument within a function

2016-02-04 Thread William Dunlap via R-help
The "missingness" of an argument gets passed down through nested function calls. E.g., fOuter <- function(x) c(outerMissing=missing(x), innerMissing=fInner(x)) fInner <- function(x) missing(x) fInner() #[1] TRUE fOuter() #outerMissing innerMissing # TRUE TRUE It is only

Re: [R] Subset with missing argument within a function

2016-02-04 Thread Stefano de Pretis
Hi Petr, Thank you for your answer. I'm not sure how the empty index reflects what I'm showing in my example. If my function was emptySubset <- function(vec) vec[] I would then agree that this was the case. But I think it's different: I'm specifically telling my function that it should have two

Re: [R] Subset with missing argument within a function

2016-02-04 Thread PIKAL Petr
Hi Help page for ?"[" says An empty index selects all values: this is most often used to replace all the entries but keep the attributes. and actually you function construction works with empty index > x<-c(1,2,5) > letters[x] [1] "a" "b" "e" > letters[] [1] "a" "b" "c" "d" "e" "f" "g" "h" "i

Re: [R] subset data using a vector

2015-11-24 Thread DIGHE, NILESH [AG/2362]
t;V046", "V047", "V048", "V049", "V050", "V051", "V052", "V053", "V054", "V055", "V056", "V057"), class = "factor"), linecode = structure(c(1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,

Re: [R] subset data using a vector

2015-11-24 Thread Jim Lemon
m1 <- c() > x <- length(plot.id) > for (i in (1:x)) { > m1 <- as.numeric(strsplit(as.character(dataset$ranges2use), > ",")[[i]]) > } > m2 > } > > I am not sure where I am making a mistake. > Thanks. > Nilesh &g

Re: [R] subset data using a vector

2015-11-23 Thread DIGHE, NILESH [AG/2362]
lit(as.character(dataset$ranges2use), ",")[[i]]) } m2 } I am not sure where I am making a mistake. Thanks. Nilesh -Original Message- From: Michael Dewey [mailto:li...@dewey.myzen.co.uk] Sent: Monday, November 23, 2015 12:11 PM To: DIGHE, NILESH [AG/2362]; r-help@r-pro

Re: [R] subset data using a vector

2015-11-23 Thread Michael Dewey
er 23, 2015 10:17 AM To: DIGHE, NILESH [AG/2362]; r-help@r-project.org Subject: Re: [R] subset data using a vector length(strsplit(as.character(mydata$ranges2use), ",")) was that what you expected? I think not. On 23/11/2015 16:05, DIGHE, NILESH [AG/2362] wrote: Dear R users,

Re: [R] subset data using a vector

2015-11-23 Thread DIGHE, NILESH [AG/2362]
NILESH [AG/2362]; r-help@r-project.org Subject: Re: [R] subset data using a vector length(strsplit(as.character(mydata$ranges2use), ",")) was that what you expected? I think not. On 23/11/2015 16:05, DIGHE, NILESH [AG/2362] wrote: > Dear R users, > I like to split

Re: [R] subset data using a vector

2015-11-23 Thread Michael Dewey
length(strsplit(as.character(mydata$ranges2use), ",")) was that what you expected? I think not. On 23/11/2015 16:05, DIGHE, NILESH [AG/2362] wrote: Dear R users, I like to split my data by a vector created by using variable "ranges". This vector will have the current range (r

Re: [R] Subset() within function: logical error

2015-06-29 Thread Rich Shepard
On Tue, 30 Jun 2015, Rolf Turner wrote: If you want a pointer to the correct syntax for subset(), try help("subset")!!! The syntax of your "extstream" function is totally screwed up, convoluted and over-complicated. Note that even if you had your "subset" argument specified correctly, the re

Re: [R] Subset() within function: logical error

2015-06-29 Thread Rolf Turner
If you want a pointer to the correct syntax for subset(), try help("subset")!!! The syntax of your "extstream" function is totally screwed up, convoluted and over-complicated. Note that even if you had your "subset" argument specified correctly, the return() call will give you only the resu

Re: [R] Subset() within function: logical error

2015-06-29 Thread Rich Shepard
On Mon, 29 Jun 2015, David Winsemius wrote: No. A pointer to the correct use of "[" is needed. Thanks, David. This puts me on the the right path. Much appreciated, Rich __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https:/

Re: [R] Subset() within function: logical error

2015-06-29 Thread Rich Shepard
On Tue, 30 Jun 2015, Steve Taylor wrote: Using return() within a for loop makes no sense: only the first one will be returned. Steve, Mea culpa. Didn't catch that. How about: alldf.B = subset(alldf, stream=='B') # etc... I used to do each stream manually, like the above, and want to

Re: [R] Subset() within function: logical error

2015-06-29 Thread David Winsemius
On Jun 29, 2015, at 5:03 PM, Rich Shepard wrote: > Moving from interactive use of R to scripts and functions and have bumped > into what I believe is a problem with variable names. Did not see a solution > in the two R programming books I have or from my Web searches. Inexperience > with ess-tra

Re: [R] Subset() within function: logical error

2015-06-29 Thread Jeff Newmiller
Well, your code is, ah, too incorrect to convey what you want out of this effort. If I were to guess based on your description, you want all of the data, not a subset. An example data frame containing what you hope to extract might be helpful. However, extracting subsets is rarely done for just

Re: [R] Subset() within function: logical error

2015-06-29 Thread Steve Taylor
Using return() within a for loop makes no sense: only the first one will be returned. How about: alldf.B = subset(alldf, stream=='B') # etc... Also, have a look at unique(alldf$stream) or levels(alldf$stream) if you want to use a for loop on each unique value. cheers, Steve -Original

Re: [R] Subset and 0 replace?

2015-05-21 Thread Vin Cheng
, 2, 2, 2, 2, 2, 2, 2, 2, 2), Wgt = >> c(0.0043574552083, >> 0.0043574552083, 0.0043574552083, 0.0043574552083, >> 0.0043574552083, 0.0043574552083, 0.0043574552083, >> 0.0043574552083, 0.0043574552083, 0.004357455208

Re: [R] Subset and 0 replace?

2015-05-21 Thread William Dunlap
83, 0.0043574552083, > 0.0043574552083), SPCLORatingValue = c(14L, 15L, 15L, > 12L, 15L, 12L, 13L, 15L, 14L, 15L, 14L)), .Names = c("WgtBand", > "Wgt", "SPCLORatingValue"), row.names = 12:22, class = "data.frame"), > V10 = stru

Re: [R] Subset and 0 replace?

2015-05-21 Thread Vin Cheng
2, 2, 2, 2, 2, 2, 2, 2), Wgt = c(0.0043574552083, 0.00435745520833333, 0.0043574552083, 0.0043574552083, 0.0043574552083, 0.0043574552083, 0.0043574552083, 0.0043574552083, 0.0043574552083, 0.0043574552083, 0.0043574552083 ), SPCLORatingVal

Re: [R] Subset and 0 replace?

2015-05-20 Thread William Dunlap
Can you show a small self-contained example of you data and expected results? I tried to make one and your expression returned a single number in a 1 by 1 matrix. library(doBy) Generation<-list( data.frame(Wgt=c(1,2,4), SPCLORatingValue=c(10,11,12)), data.frame(Wgt=c(8,16), SPCLORatingValue=

Re: [R] Subset and 0 replace?

2015-05-20 Thread Duncan Murdoch
On 20/05/2015 7:13 PM, Vin Cheng wrote: > Hi, > > I'm trying to group rows in a dataframe with SPCLORatingValue factor >16 and > summing the Wgt's that correspond to this condition. There are 100 > dataframes in a list. > > Some of the dataframes won't have any rows that have this conditio

Re: [R] subset a data frame by largest frequencies of factors

2015-03-06 Thread S Ellison
> -Original Message- > A consulting client has a large data set with a binary response > (negative) and two factors (ctry and member) which have many levels, but > many occur with very small frequencies. It is far too sparse with a model > like > glm(negative ~ ctry+member, family=binom

Re: [R] subset a data frame by largest frequencies of factors

2015-03-05 Thread David L Carlson
These two commands will compute the cell frequencies and then sort them: e <- as.data.frame(xtabs(~ctry+member, Dataset)) f <- e[order(e$Freq, decreasing=TRUE),] Then draw your subset g <- head(f, 10) or g <- f[cumsum(f$Freq)/sum(f$Freq) >.8,] Finally merge the sample with the original data a

Re: [R] subset drops S3 classes?

2014-11-12 Thread Murat Tasan
... nd nevermind, figured it out (from the final example on the Extract.data.frame page): `[.MyClass` <- function(x, i, ...) { NextMethod("[") mostattributes(RV) <- attribute(x) RV } cheers, -m On Wed, Nov 12, 2014 at 11:02 PM, Murat Tasan wrote: > And as a follow-up, I impleme

Re: [R] subset drops S3 classes?

2014-11-12 Thread Murat Tasan
And as a follow-up, I implemented a barebones as.data.frame.MyClass(...). It works when dealing with non-subsetted data frames, but fails upon a subset(...) call: > as.data.frame.MyClass <- function(x, ...) as.data.frame.vector(x, ...) This works for a single column, e.g.: > str(data.frame(MyCla

Re: [R] Subset a column with specific characters

2014-09-04 Thread David Winsemius
On Sep 4, 2014, at 2:58 PM, Kuma Raj wrote: > This post has NOT been accepted by the mailing list yet. Well, it has now. Were you earlier posting from Nabble? (Not an efficient strategy.) > I would like to subset a column based on the contents of a column with > specific character. In the samp

Re: [R] Subset, period of days like one after another in a group

2014-05-21 Thread jim holtman
try this: > x <- structure(list(date = structure(c(15765, 15766, 15767, 15768, + 15769, 15770, 15771, 15772, 15773, 15780, 15781, 15782, 15788, + 15789, 15790, 15791, 15792, 15795), class = "Date"), mon = c("Mrz", + "Mrz", "Mrz", "Mrz", "Mrz", "Mrz", "Mrz", "Mrz", "Mrz", "Mrz", + "Mrz", "Mrz", "Mr

Re: [R] Subset, period of days like one after another in a group

2014-05-20 Thread arun
Hi, In your example the "wea", only showed "dw".  Suppose the data is like this: dat1 <- structure(list(date = structure(c(15765, 15766, 15767, 15768, 15769, 15770, 15771, 15772, 15773, 15780, 15781, 15782, 15788, 15789, 15790, 15791, 15792, 15795, 15796, 15797, 15798, 15799, 15800, 15801, 1

Re: [R] Subset, period of days like one after another in a group

2014-05-20 Thread arun
Hi, #if 'dat` is the dataset May be this helps. lst1 <- setNames(split(dat, cumsum(c(TRUE,diff(dat$date)!=1))),LETTERS[1:4]) A.K. On Tuesday, May 20, 2014 12:17 PM, Christoph Schlächter wrote: Dear all, I have a subset of a data frame with 3 columns and a few rows. The columns are “date” [%

Re: [R] subset of obersevation depending on multiple conditions

2014-04-29 Thread Christoph Schlächter
Dear, This is a very efficient way. I have checked some values and it is what is was looking for. I want to find the days called dry-weather days. It depends but in my case it is a dry day if on this day the precipitation "N" is equal or less than 0.3 mm and if on the day before the day with N <=

Re: [R] subset of obersevation depending on multiple conditions

2014-04-28 Thread Frede Aakmann Tøgersen
nal Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf Of arun > Sent: 28. april 2014 13:58 > To: R. Help > Subject: Re: [R] subset of obersevation depending on multiple conditions > > Hi, > > The conditions are not very c

Re: [R] subset of obersevation depending on multiple conditions

2014-04-28 Thread Frede Aakmann Tøgersen
Hi Here is a very simple way. mydat <- read.table(text=" DateN 2010-01-010 2010-01-021.9 2010-01-030 2010-01-040 2010-01-051.6 2010-01-060 2010-01-070.3 2010-01-080 2010-01-091.1 2010-01-101.7 2010-01-112.6 2010-01-120 2010-01-130 2010-01-1

Re: [R] subset of obersevation depending on multiple conditions

2014-04-28 Thread arun
Hi, The conditions are not very clear.  Based on the rows you wanted to pick, may be this helps, #It is better to dput() the example.     dat <- structure(list(Date = structure(c(14610, 14611, 14612, 14613, 14614, 14615, 14616, 14617, 14618, 14619, 14620, 14621, 14622, 14623, 14624, 14625, 14

Re: [R] subset of obersevation depending on multiple conditions

2014-04-28 Thread Ivan Calandra
Hi Christoph, I'm not sure I understand your conditions. It is an "AND" or an "OR", i.e. must both conditions be met to subset or any one of them? From your explanation, I would think you really mean AND, but then I don't understand why you would select both lines 3 and 4. I would just say: d

Re: [R] Subset error on atomic vectors why?

2014-04-02 Thread arun
Hi, It is not mentioned whether your dataset is a matrix of data.frame.  Also, please use ?dput() to show the dataset.  I get similar errors with matrix. MOPrice <- data.frame(Date=c("2013-12-31","2013-12-31","2013-12-31","2013-11-28"),stringsAsFactors=FALSE) subset(MOPrice, as.Date(Date,"%Y-%m-

Re: [R] Subset error on atomic vectors why?

2014-04-02 Thread David Winsemius
On Apr 2, 2014, at 3:35 PM, jcrosbie wrote: > I'm getting this error: "Error in MOPrice$Date : $ operator is invalid for > atomic vectors" > > The cost is: subset(MOPrice, > as.Date(MOPrice$Date,"%Y-%m-%d")==as.Date("2013-11-28","%Y-%m-%d")) > > The date column looks like: > "2013-12-31" "2013

Re: [R] Subset for plot in R

2014-02-19 Thread Greg Snow
So are the names of the columns in the dataset x, y, and z? or are they area, concentration, and year? you seem to be mixing these together? If you provide a minimal reproducible example (provide some data with dput, or the commands to generate random data, or use a built in dataset) then it make

Re: [R] Subset for plot in R

2014-02-17 Thread arun
Hi, Try: set.seed(49)  dat1 <- data.frame(year= rep(2010:2013,c(10,8,9,13)),x=sample(1e4,40,replace=TRUE),y=sample(40,40,replace=TRUE)) plot(x~y,data=dat1,subset=year > 2012) #or with(subset(dat1,year > 2012),plot(y,x)) A.K. Hi R people This might take me the whole day to figure out, instea

Re: [R] subset of data frame

2014-02-09 Thread arun
Hi, Try: x[x$Species%in%names(sp)[1:2],] A.K. On Saturday, February 8, 2014 10:21 PM, Yuanzhi Li wrote: Hi, everyone I met a small problem when I want take a subset from a data frame. The data frame(x) looks like the followings(10 species with 3 measured traits): Species    trait1    tra

Re: [R] subset of data frame

2014-02-09 Thread Rui Barradas
Hello, First of all use ?dput to post a data example. dput(head(x, 20)) # paste the output of this in a post Now, without a reproducible example it's difficult to say but maybe ?%in% x[x$Species %in% names(sp)[1:2],] Hope this helps, Rui Barradas Em 09-02-2014 00:03, Yuanzhi Li escreveu:

Re: [R] subset a data frame into multiple data frames

2014-01-27 Thread arun
Hi, Try ?split() If `dat1` is the dataset: lst1 <- split(dat1,dat1$ID) lst1$an1 #   ID V1  mean   SD   SE #1 an1  5  72.21719 22.27118 9.092172 #2 an1  6 100.0   NA   NA lst1$an2 #   ID V1  mean   SD  SE #3 an2  5  79.27999 25.08938 10.2427 #4 an2  6 100.0 

Re: [R] subset and na.rm not really suppressing values

2014-01-24 Thread peter dalgaard
subset.data.frame() does not have an na.rm argument! -pd On 23 Jan 2014, at 00:58 , Jeff Johnson wrote: > I have a dataset "mydf" with a field EMAIL_ADDRESS. When importing, I > specified: > mydf <- read.csv(file = extract, header = TRUE, stringsAsFactors = FALSE, > na.strings=c("NA","")) > >

Re: [R] subset and na.rm not really suppressing values

2014-01-22 Thread Jeff Newmiller
I don't think na.rm is a valid at parameter for the subset function. I would normally use the is.na function to logically test for NA values. I also don't know where your VALID_EMAIL variable is coming from. a <- subset(mydf, !is.na(EMAIL_ADDRESS)) The na.strings argument to read.csv and friend

Re: [R] subset every 5th row

2014-01-19 Thread arun
Hi Veepsirtt, May be this helps: dat1 <- structure(list(V2 = c(11109.75, 11135.15, 11105.85, 11099.75, 11055.55, 11063.45, 11045.65, 11065, 11061.2, 11070.25, 11069.3, 11076, 11081.85, 11086.4, 11086.7, 11065.6, 11071.25, 11073.15, 11077.8, 11067.7, 11061.1, 11065.9, 11069.1, 11063.3, 11070.45,

Re: [R] Subset and order

2013-07-07 Thread arun
#300 1 3 10 #301 1 3  2 #437 1 3  9 #672 1 3  8 A.K. - Original Message - From: Rui Barradas To: Noah Silverman Cc: "R-help@r-project.org" Sent: Friday, July 5, 2013 3:51 PM Subject: Re: [R] Subset and order Hello, If time is one of the problems, precompute an ordered index

Re: [R] Subset and order

2013-07-05 Thread Ben Bolker
David Carlson tamu.edu> writes: > > It may be that single and efficient are opposing goals. Two steps > lets you create the subset and then just order each query. > Alternatively, if the data do not change often, create an ordered > version and query that. > I don't know the data.table pack

Re: [R] Subset and order

2013-07-05 Thread David Carlson
[mailto:r-help-boun...@r-project.org] On Behalf Of Noah Silverman Sent: Friday, July 5, 2013 2:47 PM To: Rui Barradas Cc: R-help@r-project.org Subject: Re: [R] Subset and order That would work, but is painfully slow. It forces a new sort of the data with every query. I have 200,000 rows and need

Re: [R] Subset and order

2013-07-05 Thread Rui Barradas
Hello, If time is one of the problems, precompute an ordered index, and use it every time you want the df sorted. But that would mean you can't do it in a single operation. iord <- order(x$a) subset(x[iord, ], b == 3) Rui Barradas Em 05-07-2013 20:47, Noah Silverman escreveu: That would w

Re: [R] Subset and order

2013-07-05 Thread Noah Silverman
That would work, but is painfully slow. It forces a new sort of the data with every query. I have 200,000 rows and need almost a hundred queries. Thanks, -N On Jul 5, 2013, at 12:43 PM, Rui Barradas wrote: > Hello, > > Maybe like this? > > subset(x[order(x$a), ], b == 3) > > > Hope thi

Re: [R] Subset and order

2013-07-05 Thread Rui Barradas
Hello, Maybe like this? subset(x[order(x$a), ], b == 3) Hope this helps, Rui Barradas Em 05-07-2013 20:33, Noah Silverman escreveu: Hello, I have a data frame with several columns. I'd like to select some subset *and* order by another field at the same time. Example: a b c 1

Re: [R] subset of factors in a regression

2013-07-02 Thread David Winsemius
On Jul 1, 2013, at 9:39 PM, Ben Bolker wrote: > Philip A. Viton osu.edu> writes: > >> suppose "state" is a variable in a dataframe containing abbreviations >> of the US states, as a factor. What I'd like to do is to include >> dummy variables for a few of the states, (say, CA and MA) among th

  1   2   3   4   >