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

[R] $ subset operator behavior in lapply

2022-10-27 Thread Hilmar Berger
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(a=1:3, b=LETTERS[1:3]),"B"=list(a=7:9, b=LETTERS[7:9])) > > lapply(xx,`$`,"a") $A NULL $B NULL > `$`(xx[[1]],"a") [1] 1 2 3 > lapply

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

[R] subset data frame problem

2021-12-12 Thread Kai Yang via R-help
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 the code return a wrong result. Can someone help me for this?  Thanks,Kai [[alternative HTML version deleted]] ___

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

[R] Subset command

2021-10-15 Thread Steven Yen
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. > mydata<-subset(mydata, +    prim>-9 & highsch>-9  & tert>-9 & +    govt>-9 & nongovt>-9  & +    m

Re: [R] R Subset by Factor levels

2020-07-30 Thread Engin Yılmaz
I solve this as follows m2 <- subset(m1,`Classification Description`=="Borrowing from the Public" | `Classification Description`=="By Other Means" | `Classification Description`=="Total Surplus (+) or Deficit (-)") sincerely Engin YILMAZ Engin Yılmaz , 29 Tem 2020 Çar, 16:57 tarihinde şunu yazd

Re: [R] R Subset by Factor levels

2020-07-29 Thread Rui Barradas
Hello, Try %in% instead of == in: m2<-m1[m1$`Classification Description` == levels(m1$`Classification Description`)[c(1,15,2,4],] Hope this helps, Rui Barradas Às 14:57 de 29/07/2020, Engin Yılmaz escreveu: Dear I try to create a new subset from my dataframe. My dataframe's name is m1.

Re: [R] R Subset by Factor levels

2020-07-29 Thread Rasmus Liland
Dear Engin, On 2020-07-29 16:57 +0300, Engin Yılmaz wrote: > Dear > > I try to create a new subset from my dataframe. > My dataframe's name is m1. > "Classification Description" column has 15 different factors. > The following code is used creating a subset for 1 factor. > m2<-m1[m1$`Classificati

[R] R Subset by Factor levels

2020-07-29 Thread Engin Yılmaz
Dear I try to create a new subset from my dataframe. My dataframe's name is m1. "Classification Description" column has 15 different factors. The following code is used creating a subset for 1 factor. m2<-m1[m1$`Classification Description` == levels(m1$`Classification Description`)[1],] My aim is

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

[R] Subset a data frame with specific date

2020-01-13 Thread ani jaya
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 date rmm1 rmm2 phase amp 1 1986 11 -0.326480 -1.55895 2 1.59277 2 1

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

[R] subset English language using textcat package

2018-11-19 Thread Elahe chalabi via R-help
Hi all, How is it possible to subset English text from a df containing German and English texts using textcat package? > library(textcat) > dput(data) structure(list(x = structure(c(2L, 6L, 5L, 3L, 1L, 4L), .Label = c("Dieses Buch ist erstaunlich", "I love this book", "ich

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

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

2018-09-27 Thread Knut Krueger
Hi to all I need a subset for values if there are f.e 3 values successive in a column of a Data Frame: Example from the subset help page: subset(airquality, Temp > 80, select = c(Ozone, Temp)) 29 45 81 35 NA 84 36 NA 85 38 29 82 39 NA 87 40 71 90 41 39

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

[R] Subset Rasterbrick by time

2018-06-18 Thread Miluji Sb
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.Date("2000-01-01 10:30:00") & getZ(original ) <= as.Date("2014-12-31 10

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

[R] Subset

2017-09-22 Thread Shane Carey
Hi, How do I extract just numbers from the following list: a=c("<0.1",NA,0.3,5,Nil) so I want to obtain: 0.3 and 5 from the above list Thanks -- Le gach dea ghui, *Shane Carey* *GIS and Data Solutions Consultant* [[alternative HTML version deleted]]

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

[R] Subset()

2017-01-20 Thread Elise LIKILIKI
Hello, I have a dataset containing Date Time, Air Temperature, PPFD, Sol Temperature... The first data are false so I would like to extract the other ones. I've tried : >data1<-subset(data,DateTime>=as.POSIXct("2017-01-10 11:00:00",format="%Y-%m-%d %H:%M:%S"),select=c(DateTime,PPFD_Avg,Air_Temp_Av

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,

[R] Subset and sumerize

2016-10-14 Thread Ashta
Hi all, I am trying to summarize big data set by selecting a row conditionally. and tried to do it in a loop Here is the sample of my data and my attempt dat<-read.table(text=" ID,x1,x2,y 1,a,b,15 1,x,z,21 1,x,b,16 1,x,k,25 2,d,z,31 2,x,z,28 2,g,t,41 3,h,e,32 3,x,z,38 3,x,g,45 ",sep=",",he

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

[R] subset data right

2016-05-26 Thread ch.elahe via R-help
Hi all, I have the following df and I want to know which Protocols are VeryFast, which are FAST, which are SLOW and also which ones are VerySLOW : $ Protocol : Factor w/ 48 levels "DP FS QTSE SAG",..: 5 5 28 5 5 5 7 7 47 5 ... $ quant : Factor w/ 4 levels "FAST","SLOW",.

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

[R] subset by multiple letters condition

2016-04-22 Thread ch.elahe via R-help
Hi all, I have a data frame df and I want to do subset based on several conditions of letters of the names in Command.1)if the names contain PD 2)if the names contain t1 3)if the names contain t2 4)if the names contain t1 and PD 5)if the names contain t2 and PD 6)otherwise the names would be

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

2016-02-05 Thread William Dunlap via R-help
n 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&qu

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

2016-02-04 Thread Stefano de Pretis
>> > > letters[] >> > [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" >> > "r&q

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

2016-02-04 Thread William Dunlap via R-help
"e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" > > "r" "s" > > [20] "t" "u" "v" "w" &qu

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

2016-02-04 Thread Stefano de Pretis
w" "x" "y" "z" > > It is sometimes useful not "expect" the program behavior but "inspect" why > it behaves differently. > > If you want your function to throw error when some arguments are missing > you need to do the check y

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

2016-02-04 Thread PIKAL Petr
quot; "u" "v" "w" "x" "y" "z" It is sometimes useful not "expect" the program behavior but "inspect" why it behaves differently. If you want your function to throw error when some arguments are missing you need to do

[R] Subset with missing argument within a function

2016-02-04 Thread Stefano de Pretis
Hi all, I'm guessing what's the rationale behind this: > subsettingFun <- function(vec, ix) vec[ix] > subsettingFun(letters, c(1,2,5)) [1] "a" "b" "e" > subsettingFun(letters) [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" [20] "t" "u" "v" "w" "x" "y" "z" If the

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

[R] subset data using a vector

2015-11-23 Thread DIGHE, NILESH [AG/2362]
Dear R users, I like to split my data by a vector created by using variable "ranges". This vector will have the current range (ranges), preceding range (ranges - 1), and post range (ranges + 1) for a given plotid. If the preceding or post ranges in this vector are outside the l

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
Steve -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rich Shepard Sent: Tuesday, 30 June 2015 12:04p To: r-help@r-project.org Subject: [R] Subset() within function: logical error Moving from interactive use of R to scripts and functions and have bumped i

[R] Subset() within function: logical error

2015-06-29 Thread Rich Shepard
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-tracebug keeps me from refining my bug tracking. Here's a

[R] subset svydesign problem

2015-06-03 Thread Daniela Droguett
Hi, it seems not possible to susbset a svydesign object (DBI svydesign) and use variables to make the subset expression uff<-c("14","15") for (i in 1:length(uff)) { subpnad<-subset(pnad, uf==uff[i] & v0302=='4') } the error is the following Error in sqliteSendQuery(con, statement, bind.data)

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

[R] Subset and 0 replace?

2015-05-20 Thread Vin Cheng
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 condition SPCLORatingValue>16 and therefore no corresponding

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
X 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Michael Friendly Sent: Thursday, March 5, 2015 12:45 PM To: R-help Subject: [R] subset a data frame by largest frequencies of factors A consulting client has a large data set with a binary response

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

2015-03-05 Thread Michael Friendly
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=binomial). > str(Dataset) 'data.frame': 1

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

[R] subset drops S3 classes?

2014-11-12 Thread Murat Tasan
Hi all --- I've stumbled upon some pretty annoying behavior, and I'm curious how others may have gotten around it. When using subset(...) on a data frame that contains a custom S3 field, the class is dropped in the result: > MyClass <- function(x) structure(x, class = "MyClass") > df <- data.fram

[R] subset ffdf does not accept bit vector anymore (package ffbase)

2014-09-25 Thread christian.kamenik
Hi everyone Since I updated package 'ffbase', subset.ffdf does not work with bit vectors anymore. Here is a short example: data(iris) library(ffbase) iris.ffdf <- as.ffdf(iris) index <- sample(c(FALSE,TRUE), nrow(iris), TRUE) index.bit <- as.bit(index) subset(iris.ffdf, subset=index.bit) resu

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

[R] Subset a column with specific characters

2014-09-04 Thread Kuma Raj
This post has NOT been accepted by the mailing list yet. I would like to subset a column based on the contents of a column with specific character. In the sample data I wish to do the following: First keep the data based on column "prog" if prog contains "ca", and secondly to drop if race contains

  1   2   3   4   5   6   >