Re: [R] Subsetting a vector using an index with all missing values

2022-07-02 Thread Peter Langfelder
Ah, thanks, that makes sense. Peter On Fri, Jul 1, 2022 at 10:01 PM Bill Dunlap wrote: > > This has to do with the mode of the subscript - logical subscripts are > repeated to the length of x and integer/numeric ones are not. NA is logical, > NA_integer_ is integer, so we get > > > x <- 1:10

[R] subsetting/slicing xml2 nodesets

2019-08-21 Thread Tobias Fellinger
Dear R-help members, I'm working with the xml2 package to parse an xml document, and I don't understand how subsetting / slicing of xml_nodesets works. I'd expect xml_find_all to only return children of the nodes I selected with [ or [[ but it returns all nodes found in the whole document. I

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

[R] Subsetting Data from a Dataframe

2019-05-24 Thread Paul Bernal
Dear friends, Hope you are all doing well. I would like to know how to retrieve a complete dataframe (all the columns), except for the cases when one of the columns have either nulls or NAs. In this case, I´d like to retrieve all the columns but only the cases (rows) where Var5 has values

Re: [R] subsetting ls() as per class...

2018-07-28 Thread akshay kulkarni
dear peter, Its workingthanks a lot... yours sincerely, AKSHAY M KULKARNI From: Peter Langfelder Sent: Saturday, July 28, 2018 11:41 AM To: akshay...@hotmail.com Cc: r-help Subject: Re: [R] subsetting ls() as per class... Looking at ?rm

Re: [R] subsetting ls() as per class...

2018-07-28 Thread William Dunlap via R-help
> objClasses <- unlist(eapply(.GlobalEnv, function(x)class(x)[1])) > head(objClasses) f E "function" "environment" df h "tbl_df""function" myData L "list""list" > names(objClasses)[objClasses=="tbl_df"]

Re: [R] subsetting ls() as per class...

2018-07-28 Thread Henrik Bengtsson
The ll() function of R.oo returns a data.frame with various attributes that you can subset on, e.g. > subset(R.oo::ll(), data.class %in% c("zoo", "xts")) member data.class dimension objectSize 2 fzzoo10 1344 4 sample.xtsxts c(180,4) 10128 5

Re: [R] subsetting ls() as per class...

2018-07-28 Thread Jeff Newmiller
You can extract the names into a character vector with ls and then use grep(..., values=TRUE ) to select which ones you want to remove, and then pass that list to rm. However, due to the way R handles memory you are unlikely to see much savings by doing this. I would recommend focusing on

Re: [R] subsetting ls() as per class...

2018-07-28 Thread Peter Langfelder
Looking at ?rm, my solution would be something like rm(list = grep("\\.NS$", ls(), value = TRUE)) But test it since I have not tested it. Peter On Fri, Jul 27, 2018 at 10:58 PM akshay kulkarni wrote: > > dear memebers, >I am using R in AWS linux instance for

[R] subsetting ls() as per class...

2018-07-27 Thread akshay kulkarni
dear memebers, I am using R in AWS linux instance for my research. I want to remove certain objects from the global environment to reduce my EBS cost..for example, I want to remove all objects of class "xts", "zoo". Is there any way to automate this, instead of

Re: [R] subsetting lists....

2018-06-18 Thread MacQueen, Don via R-help
The unlist solution is quite clever. But I will note that none of the solutions offered so far succeed if the input is, for example, YH <- list(1:5, letters[1:3], 1:7) iuhV <- c(2,2,4) and the desire is to return a list whose elements are of the same types as the input list. Which

Re: [R] subsetting lists....

2018-06-18 Thread Berry, Charles
> On Jun 18, 2018, at 4:15 AM, akshay kulkarni wrote: > > correctionI want the method without a for loop Here are two. The first is more readable, but the second is 5 times faster. mapply("[", YH, iuhV) unlist(YH, recursive = FALSE, use.names = FALSE)[cumsum( lengths(YH)) -

Re: [R] subsetting lists....

2018-06-18 Thread Eric Berger
sapply( 1:length(YH), function(i) { YH[[i]][iuhV[i]]}) On Mon, Jun 18, 2018 at 1:55 PM, akshay kulkarni wrote: > dear members, > I have list YH and index vector iuhV. I want > to select iuhV[1] from YH[[1]], iuhv[2] from YH[[2]], iuhv[3] from > YH[[3]]..iuhv[n]

[R] subsetting lists....

2018-06-18 Thread akshay kulkarni
dear members, I have list YH and index vector iuhV. I want to select iuhV[1] from YH[[1]], iuhv[2] from YH[[2]], iuhv[3] from YH[[3]]..iuhv[n] from YH[[n]]... How to do this? I searched SO and the internet but was bootless Very many thanks for your time and

[R] Subsetting comparison problem

2018-03-11 Thread Neha Aggarwal
Hello All, I am facing a unique problem and am unable to find any help in R help pages or online. I will appreciate your help for the following problem: I have 2 data-frames, samples below and there is an expected output R Dataframe1: C1 C2 C3 C4.. CN R1

Re: [R] subsetting comparison problem

2018-03-11 Thread Jim Lemon
Hi Neha, This might help: R<-read.table(text="C1 C2 C3 C4 R1 0 1 0 1 R2 1 0 1 1 R3 1 0 0 0", header=TRUE) U<-read.table(text="C1 C2 C3 C4 U1 1 1 0 1 U2 1 1 1 1", header=TRUE) # these are matrices - I think this will work for dataframes as well for(ui in 1:dim(U)[1]) { for(ri in 1:dim(R)[1]) {

Re: [R] subsetting comparison problem

2018-03-11 Thread David Winsemius
> On Mar 11, 2018, at 3:32 PM, Neha Aggarwal wrote: > > Hello All, > I am facing a unique problem and am unable to find any help in R help pages > or online. I will appreciate your help for the following problem: > I have 2 data-frames, samples below and there is an

Re: [R] subsetting comparison problem

2018-03-11 Thread Jeff Newmiller
Responses inline. On Sun, 11 Mar 2018, Neha Aggarwal wrote: Hello All, I am facing a unique problem and am unable to find any help in R help pages or online. I will appreciate your help for the following problem: I have 2 data-frames, samples below and there is an expected output R

[R] subsetting comparison problem

2018-03-11 Thread Neha Aggarwal
Hello All, I am facing a unique problem and am unable to find any help in R help pages or online. I will appreciate your help for the following problem: I have 2 data-frames, samples below and there is an expected output R Dataframe1: C1 C2 C3 C4.. CN R1

Re: [R] subsetting

2016-02-24 Thread Val
Thank you for the info. I did solve it using unlist lapply strsplit functions. On Wed, Feb 24, 2016 at 9:31 PM, Bert Gunter wrote: > Have you gone through any R tutorials yet? I didn't entirely > understand your question (and so cannot answer), but this sounds like > a

Re: [R] subsetting

2016-02-24 Thread Ryan Derickson
A combination of subsetting and ?substr should get you close to a solution. If the middle sequence you referenced isn't always the same distance from the first character, you may have to involve regular expressions to find "the middle". On Wednesday, February 24, 2016, Bert Gunter

Re: [R] subsetting

2016-02-24 Thread Bert Gunter
Have you gone through any R tutorials yet? I didn't entirely understand your question (and so cannot answer), but this sounds like a basic subsetting/data wrangling task that you should know how to do if you have gone through a basic tutorial or two. See also ?subset, ?"[" (basic indexing) and

[R] subsetting

2016-02-24 Thread Val
Hi all, One of the the columns of a data frame has a value such like S-2001-yy S-2004-xx F-2007-SS and so on based on this column (variable) I want subset a data frame where the middle value of this variable is between 2001 to 2004. THE END RESULT THE DATA FRAME WILL BE THIS.

Re: [R] Subsetting a square marix

2016-01-05 Thread Sarah Goslee
It really isn't clear what you want, and posting in HTML has mangled what you did provide. Please use dput() to provide sample data, and give us a clear idea of what you want, ideally an example of what the output should look like. Adding the R code you've tried to use is also a good idea. Sarah

[R] Subsetting a square marix

2016-01-05 Thread Tawanda Tarakini
I have a global matrix (e.g. table below) of species feeding. I am trying to create specific matrix for specific sites. If for example a subset is to have sp1, sp3 and spp only these 3 species should be appearing in the subset (both column and rows). I have been checking online help but I seem

Re: [R] Subsetting a square marix

2016-01-05 Thread David L Carlson
orials so that you understand how R works. - David L Carlson Department of Anthropology Texas A University College Station, TX 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Sarah Goslee Sent: Tuesday, Jan

Re: [R] Subsetting dataframe by the nearest values of a vector elements

2015-11-10 Thread Harun Rashid via R-help
HI Jean, Here is part of my data. As you can see, I have cross-section point and corresponding elevation of a river. Now I want to select cross-section points by 50m interval. But the real cross-section data might not have exact points say 0, 50, 100,…and so on. Therefore, I need to take points

Re: [R] Subsetting dataframe by the nearest values of a vector elements

2015-11-09 Thread David Winsemius
> On Nov 9, 2015, at 9:19 AM, Adams, Jean wrote: > > Harun, > > Can you give a simple example? > > If your cross_section looked like this > c(144, 179, 214, 39, 284, 109, 74, 4, 249) > and your other vector looked like this > c(0, 50, 100, 150, 200, 250, 300, 350) > what

Re: [R] Subsetting dataframe by the nearest values of a vector elements

2015-11-09 Thread jim holtman
Do you want the "closest" or what range it is in? If you want the range, then use 'cut': > x <- c(144, 179, 214, 39, 284, 109, 74, 4, 249) > range <- c(0, 50, 100, 150, 200, 250, 300, 350) > result <- cut(x, breaks = range) > cbind(x, as.character(result)) x [1,] "144" "(100,150]" [2,]

Re: [R] Subsetting dataframe by the nearest values of a vector elements

2015-11-09 Thread Adams, Jean
Harun, Can you give a simple example? If your cross_section looked like this c(144, 179, 214, 39, 284, 109, 74, 4, 249) and your other vector looked like this c(0, 50, 100, 150, 200, 250, 300, 350) what would you want your subset to look like? Jean On Mon, Nov 9, 2015 at 7:26 AM, Harun Rashid

[R] Subsetting dataframe by the nearest values of a vector elements

2015-11-09 Thread Harun Rashid via R-help
Hello, I have a dataset with two columns 1. cross_section (range: 0~635), and 2. elevation. The dataset has more than 100 rows. Now I want to make a subset on the condition that the 'cross_section' column will pick up the nearest cell from another vector (say 0, 50,100,150,200,.,650). How

[R] subsetting a data.frame based on a specific group of columns

2015-11-06 Thread Assa Yeroslaviz
Hi, I have a data frame with multiple columns, which are belong to several groups like that: X1X2X3Y1Y2Y3 1232357230987172 0719811795743 4391907614 I would like to filter such rows out, where the sums in one

Re: [R] subsetting a data.frame based on a specific group of columns

2015-11-06 Thread jim holtman
Is this what you want: > x <- read.table(text = "X1X2X3Y1Y2Y3 + 1232357230987172 + 0719811795743 + 4391907614", header = TRUE) > x X1 X2 X3 Y1 Y2 Y3 1 1232 357 23 0 9871 72 20 719 811 795

Re: [R] subsetting a data.frame based on a specific group of columns

2015-11-06 Thread Boris Steipe
Please learn to use dput() to post example data. # This is your data: data <- structure(c(1232, 0, 43, 357, 71, 919, 23, 9, , 0, 811, 0, 9871, 795, 76, 72, 743, 14), .Dim = c(3L, 6L), .Dimnames = list( NULL, c("X1", "X2", "X3", "Y1", "Y2", "Y3"))) data # define groups and threshold

Re: [R] subsetting a data.frame based on a specific group of columns

2015-11-06 Thread jim holtman
I assume the solution is somewhat the same; you just have to define how to determine what the "distinctive" names are to create the groupings. My solution assumed it was the first character. If the group names end in a unique sequence, you can use this to form the groups, or you can provide a

Re: [R] subsetting a data.frame based on a specific group of columns

2015-11-06 Thread Assa Yeroslaviz
sorry, for the misunderstanding. here is a more elaborate description of what i would like to achieve. I have a data set of counts from a RNA-Seq experiment and would like to filter reads with low counts. I don't want to set everything to 0 automatically. I would like to set each categorical

Re: [R] subsetting a dataframe

2015-06-09 Thread Ryan Derickson
Lots of ways to do this, I use %in% with bracket notation [row, column]. The empty column argument below returns all columns but you could have conditional logic there as well. dd[dd$rows %in% test_rows, ] On Mon, Jun 8, 2015 at 6:44 PM, Bogdan Tanasa tan...@gmail.com wrote: Dear all,

[R] subsetting a dataframe

2015-06-08 Thread Bogdan Tanasa
Dear all, would appreciate your suggestions on subsetting a dataframe : please let's consider an example dataframe df: dd-c(1,2,3) rows-c(A1,A2,A3) columns-c(B1,B2,B3) numbers - c(400, 500, 600) df - dataframe(dd,rows,columns, numbers) and a vector : test_rows -c(A1,A3) ; how could I subset

Re: [R] subsetting a dataframe

2015-06-08 Thread William Dunlap
Use is.element(elements,set), or its equivalent, elements %in% set: df - data.frame(dd = c(1, 2, 3), rows = c(A1, A2, A3), columns = c(B1, B2, B3), numbers = c(400, 500, 600)) test_rows -c(A1,A3) df[ is.element(df$rows, test_rows), ] # dd rows

[R] subsetting question

2015-05-20 Thread Dieter Anseeuw
Dear all, I would like to do multiple actions on a subset of my data. Therefore, I want to create a for loop on the variable Date (actually a double for loop on yet another variable, but let's omit that for a moment). I want to run down every level of Date and perform multiple actions on the

Re: [R] subsetting question

2015-05-20 Thread MacQueen, Don
Assuming datums is a vector of the unique dates in Date... perhaps datums - sort(unique(dataset1$Date)) I usually set it up like this for (i in 1:length(datums) ) { crnt.date - datums[i] tmpdat - subset(dataset1, Date==crnt.date) cat(i, format(crnt.date),

Re: [R] subsetting question

2015-05-20 Thread William Dunlap
Here is a self-contained example of what you might be trying to do. You would get better answers if you supplied this yourself. dataset1 - data.frame(Date=as.POSIXct(c(2015-04-01,2015-04-01,2015-04-07, 2015-04-19)), Weight=11:14) datums - as.POSIXct(c(2015-04-01, 2015-04-08, 2015-04-19)) # note

Re: [R] subsetting question

2015-05-20 Thread Ivan Calandra
Hi, What about using functions like aggregate()? Something like: aggregate(Weight~datums, data=dataset1, FUN=mean) If you need to do more things, you can create your own function for 'FUN' HTH, Ivan -- Ivan Calandra, ATER University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2

[R] Subsetting from pareto distribution

2015-04-28 Thread W Z
I have a dataset of 20k records heavily right skewed as pareto distribution, I'd like to pull 1k subset of it with same distribution, any R package would do that? Thanks. [[alternative HTML version deleted]] __ R-help@r-project.org mailing

Re: [R] Subsetting from pareto distribution

2015-04-28 Thread David Winsemius
On Apr 28, 2015, at 12:20 PM, W Z wrote: I have a dataset of 20k records heavily right skewed as pareto distribution, I'd like to pull 1k subset of it with same distribution, any R package would do that? Why not just: subdat - dat[sample( nrow(dat), 1000), ] # if dataset is a dataframe

Re: [R] Subsetting a list of lists using lapply

2015-02-20 Thread Aron Lindberg
Thanks Chuck and Rolf. While Rolf’s code also works on the dput that I actually gave you (a smaller subset of the full dataset), it failed to work on the larger dataset, because there are further exceptions: input[[i]]$content[[1]] is sometimes a list, sometimes a character vector, and

Re: [R] Subsetting a list of lists using lapply

2015-02-20 Thread Aron Lindberg
Hmm…Chuck’s solution may actually be problematic because there are several entries which at the deepest level are called “sha”, but that should not be included, such as: input[[67]]$content[[1]]$commit$tree$sha and input[[67]]$content[[1]]$parents[[1]]$sha it’s only the “sha”

Re: [R] Subsetting a list of lists using lapply

2015-02-20 Thread Bert Gunter
How can you expect a solution if you cannot specify the problem? -- Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. Clifford Stoll On Fri, Feb 20, 2015 at 6:13 AM, Aron Lindberg

Re: [R] Subsetting a list of lists using lapply

2015-02-20 Thread Charles C. Berry
On Fri, 20 Feb 2015, Aron Lindberg wrote: Hmm…Chuck’s solution may actually be problematic because there are several entries which at the deepest level are called “sha”, but that should not be included, such as: input[[67]]$content[[1]]$commit$tree$sha and

Re: [R] Subsetting a list of lists using lapply

2015-02-20 Thread David Winsemius
On Feb 20, 2015, at 6:13 AM, Aron Lindberg wrote: Hmm…Chuck’s solution may actually be problematic because there are several entries which at the deepest level are called “sha”, but that should not be included, such as: input[[67]]$content[[1]]$commit$tree$sh and

Re: [R] Subsetting a list of lists using lapply

2015-02-20 Thread William Dunlap
The elNamed(x, name) function can simplify this code a bit. The following gives the same result as David W's get_shas() for the sample dataset provided: get_shas2 - function (input) { lapply(input, function(el) elNamed(elNamed(el, content)[[1]], sha)[1]) } Bill Dunlap TIBCO

[R] Subsetting a list of lists using lapply

2015-02-19 Thread Aron Lindberg
Hi Everyone, I'm working on a thorny subsetting problem involving list of lists. I've put a dput of the data here: https://gist.githubusercontent.com/aronlindberg/b916dee897d051ac5be5/raw/a78cbf873a7e865c3173f943ff6309ea688c653b/dput I can get one intense of the element I want this

Re: [R] Subsetting a list of lists using lapply

2015-02-19 Thread Rolf Turner
On 20/02/15 08:45, Aron Lindberg wrote: Hi Everyone, I'm working on a thorny subsetting problem involving list of lists. If you think this is thorny you ain't seen nothin' yet! But note that you've got a list of lists of lists ... i.e. the nesting is at least 3 deep. I've put a dput of

Re: [R] Subsetting a list of lists using lapply

2015-02-19 Thread Charles Berry
Aron Lindberg aron.lindberg at case.edu writes: Hi Everyone, I'm working on a thorny subsetting problem involving list of lists. I've put a dput of the data here: https://gist.githubusercontent.com/aronlindberg/b916dee897d051ac5be5/

[R] Subsetting data with svyglm

2015-02-11 Thread Brennan O'Banion
I am aware that it is possible to specify a subset with a single logical operator when constructing a model, such as: svyglm(formula, design=data, subset=variable==value). What I can't figure out is how to specify a subset with two or more logical operators: svyglm(formula, design=data,

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

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

[R] Subsetting R 3.1.2

2014-12-05 Thread Dinesh Chowdhary
x - list(seq = 3:7, alpha = c(a, b, c)) x$alpha [1] a b c x[alpha] $alpha [1] a b c x[c(1,2)] $seq [1] 3 4 5 6 7 $alpha [1] a b c * x[c(1, alpha[2])]* *$NA* *NULL* *$NA* *NULL* How to access a character subset withing a list? Thank you for your effort... [[alternative HTML

Re: [R] Subsetting R 3.1.2

2014-12-05 Thread Lee, Chel Hee
Your question is not clear to me. x$alpha[1:2] [1] a b x$alpha[2] [1] b Is this what you are looking for? I hope this helps. Chel Hee Lee On 12/5/2014 11:12 AM, Dinesh Chowdhary wrote: x - list(seq = 3:7, alpha = c(a, b, c)) x$alpha [1] a b c x[alpha] $alpha [1] a b c x[c(1,2)]

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

2014-08-22 Thread Angela Boag
Hi all, I'm doing some within-dataset model validation and would like to subset a dataset 70/30 and fit a model to 70% of the data (the training data), then validate it by predicting the remaining 30% (the testing data), and I would like to do this split-sample validation 1000 times and average

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

2014-08-22 Thread David L Carlson
-project.org] On Behalf Of Angela Boag Sent: Thursday, August 21, 2014 4:46 PM To: r-help@r-project.org Subject: [R] Subsetting data for split-sample validation, then repeating 1000x Hi all, I'm doing some within-dataset model validation and would like to subset a dataset 70/30 and fit a model to 70

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

2014-08-22 Thread David L Carlson
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 feedback. I actually sampled without replacement

Re: [R] subsetting to exclude different values for each subject in study

2014-05-27 Thread Monaly Mistry
Hi Arun, Thank you for your help, I have a few questions though if you don't mind. I'm a bit confused about the following 2 lines of code: col.tri.nb - tri2nb(coords, row.names=ind) lapply(col.tri.nb,function(x) ind[x])[1:5] ## from what I understand in the first line determines the

Re: [R] subsetting to exclude different values for each subject in study

2014-05-27 Thread arun
Hi Monaly, According to the description of ?tri2nb The function uses the ‘deldir’ package to convert a matrix of two-dimensional coordinates into a neighbours list of class ‘nb’ with a list of integer vectors containing neighbour region number ids. So, col.tri.nb is a list of

Re: [R] subsetting to exclude different values for each subject in study

2014-05-23 Thread Monaly Mistry
, 22 May 2014 16:31:39 +0100 To: smartpink...@yahoo.com, r-help@r-project.org Subject: Re: [R] subsetting to exclude different values for each subject in study Hi, Sorry I'm fairly new to R and I don't really understand using dput(), when you say reproducible

Re: [R] subsetting to exclude different values for each subject in study

2014-05-23 Thread Frede Aakmann Tøgersen
/notice If you have received this e-mail in error please contact the sender. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Monaly Mistry Sent: 23. maj 2014 12:34 To: arun; r-help@r-project.org Subject: Re: [R] subsetting

Re: [R] subsetting to exclude different values for each subject in study

2014-05-23 Thread Monaly Mistry
Mistry Sent: 23. maj 2014 12:34 To: arun; r-help@r-project.org Subject: Re: [R] subsetting to exclude different values for each subject in study Hi, I did use the library deldir, I didn't put that code in since I wasn't sure if it was really relevant to the question as I just

Re: [R] subsetting to exclude different values for each subject in study

2014-05-23 Thread arun
/notice If you have received this e-mail in error please contact the sender. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Monaly Mistry Sent: 23. maj 2014 12:34 To: arun; r-help@r-project.org Subject: Re: [R] subsetting

Re: [R] subsetting to exclude different values for each subject in study

2014-05-23 Thread arun
Hi, Sorry, there is a mistake. XO[2,] should be: XO[2,] -  sapply(seq_along(col.tri.nb), function(i){ind1 - as.character(ind[i]); ind2 - as.character(ind[col.tri.nb[[i]]]); mean(abs(XO[1,ind1]-XO[1,ind2]))} ) A.K. On Friday, May 23, 2014 12:56 PM, arun smartpink...@yahoo.com wrote: Hi

[R] subsetting to exclude different values for each subject in study

2014-05-22 Thread Monaly Mistry
Hi, I've written a code to determine the difference in score for a single subject and its non-neighbours o-(ao[,c(13,5)]) ##this is the table with the relevant information o-na.omit(o) ##omitted data with NA o-o[!o$NestkastNummer %in% c(176,140,162,713),] ##removed neighbours

Re: [R] subsetting to exclude different values for each subject in study

2014-05-22 Thread Monaly Mistry
Hi, Sorry I'm fairly new to R and I don't really understand using dput(), when you say reproducible example do you mean the code with the output? Best, Monaly. On Thu, May 22, 2014 at 4:03 PM, arun smartpink...@yahoo.com wrote: Hi, It would be helpful if you provide a reproducible example

Re: [R] subsetting to exclude different values for each subject in study

2014-05-22 Thread Bert Gunter
Follow the link at the bottom of this message! -- Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 Data is not information. Information is not knowledge. And knowledge is certainly not wisdom. H. Gilbert Welch On Thu, May 22, 2014 at 8:31 AM, Monaly Mistry

Re: [R] subsetting to exclude different values for each subject in study

2014-05-22 Thread Monaly Mistry
- From: monaly.mis...@gmail.com Sent: Thu, 22 May 2014 16:31:39 +0100 To: smartpink...@yahoo.com, r-help@r-project.org Subject: Re: [R] subsetting to exclude different values for each subject in study Hi, Sorry I'm fairly new to R and I don't really understand using dput(), when you

Re: [R] subsetting to exclude different values for each subject in study

2014-05-22 Thread Monaly Mistry
(dat1) John Kane Kingston ON Canada -Original Message- From: monaly.mis...@gmail.com Sent: Thu, 22 May 2014 16:31:39 +0100 To: smartpink...@yahoo.com, r-help@r-project.org Subject: Re: [R] subsetting to exclude different values for each subject in study Hi

[R] Subsetting data by ID with different constraints

2014-04-04 Thread Lib Gray
Hello, I have a data set with many individuals all with multiple timed observations, and I would like to subset the data to exclude later timed observations. However, I would like to exclude different amounts of data for each individual. These individuals have two types of data: DV and dose. What

[R] Subsetting a dataframe by dynamic column name

2014-03-27 Thread Sneha Bishnoi
Hi all! I am trying to drop columns from a data frame dynamically depending on user input. The dataframe whose columns need to be dropped is called Finaldata So here is what I do: V is a dataframe with columns v1 and v2 as follows v1 v2 1 1 Shape 2 0 Length 3 0

Re: [R] Subsetting a dataframe by dynamic column name

2014-03-27 Thread Sarah Goslee
There are many ways. You're making it overly complicated Here, in an actual reproducible example (as you were requested to submit): V - data.frame(v1=c(1,0,0), v2=c(Shape, Length, Rate), stringsAsFactors=FALSE) Finaldata - data.frame(Shape = runif(5), Length = runif(5), Rate = runif(5)) #

Re: [R] Subsetting a dataframe by dynamic column name

2014-03-27 Thread Sneha Bishnoi
Hi Sarah, Thanks! Do agree its over complicated. However looking at the solutions I think I did not state my problem completely. V provides choices for only certain set of columns in Finaldata. So v2 may not represent all columns of Finaldata. I want to retain columns not provided as a choice for

Re: [R] Subsetting a dataframe by dynamic column name

2014-03-27 Thread David Carlson
Subject: Re: [R] Subsetting a dataframe by dynamic column name Hi Sarah, Thanks! Do agree its over complicated. However looking at the solutions I think I did not state my problem completely. V provides choices for only certain set of columns in Finaldata. So v2 may not represent all columns

Re: [R] Subsetting a dataframe by dynamic column name

2014-03-27 Thread Sneha Bishnoi
-help-boun...@r-project.org] On Behalf Of Sneha Bishnoi Sent: Thursday, March 27, 2014 11:06 AM To: Sarah Goslee Cc: r-help Subject: Re: [R] Subsetting a dataframe by dynamic column name Hi Sarah, Thanks! Do agree its over complicated. However looking at the solutions I think I did not state my

Re: [R] Subsetting between two values (into a range)????

2014-03-10 Thread arun
Hi, If 'dat' is the dataset: Try subset(dat, Start MapInfo End MapInfo) A.K. Dear All, I want to subset a column (MapInfo in the attached photo) in csv file if its values be ranged between values in two other columns (Start and End in the attached photo) using R 3.0.1. Thank you in

Re: [R] Subsetting between two values (into a range)????

2014-03-10 Thread Duncan Murdoch
On 14-03-10 10:47 AM, arun wrote: Hi, If 'dat' is the dataset: Try subset(dat, Start MapInfo End MapInfo) A bit of advice I think I read in The Elements of Programming Style: try to make complex conjunctions look like their mathematical equivalents, and they'll be easier to read. The

[R] Subsetting a named list of parameters in mle

2014-02-15 Thread John Hodgson
I have a 7-parameter model to fit using mle. I would like to generate fits for all pairs of parameters (with others fixed) The following code looked like it should work: library(stats4) # dummy mll function for sake of example mll = function

Re: [R] Subsetting a named list of parameters in mle

2014-02-15 Thread Bert Gunter
fit is initialized as a vector of integers. How can you assign an mle fit to an element of an integer vector? Initialize fit as a list, use lapply, or whatever. Have you read An Intro to R (ships with R) or other R (e.g. web) tutorial? This looks like the sort of basic misunderstanding that one

[R] Subsetting on multiple criteria (AND condition) in R

2014-01-14 Thread Jeff Johnson
I'm running the following to get what I would expect is a subset of countries that are not equal to US AND COUNTRY is not in one of my validcountries values. non_us - subset(mydf, (COUNTRY %in% validcountries) COUNTRY != US, select = COUNTRY, na.rm=TRUE) however, when I then do table(non_us) I

Re: [R] Subsetting on multiple criteria (AND condition) in R

2014-01-14 Thread arun
Hi, Try: table(as.character(non_us[,COUNTRY])) A.K. On Tuesday, January 14, 2014 3:17 PM, Jeff Johnson mrjeffto...@gmail.com wrote: I'm running the following to get what I would expect is a subset of countries that are not equal to US AND COUNTRY is not in one of my validcountries values.

Re: [R] Subsetting on multiple criteria (AND condition) in R

2014-01-14 Thread Marc Schwartz
On Jan 14, 2014, at 1:38 PM, Jeff Johnson mrjeffto...@gmail.com wrote: I'm running the following to get what I would expect is a subset of countries that are not equal to US AND COUNTRY is not in one of my validcountries values. non_us - subset(mydf, (COUNTRY %in% validcountries) COUNTRY

Re: [R] Subsetting on multiple criteria (AND condition) in R

2014-01-14 Thread William Dunlap
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Johnson Sent: Tuesday, January 14, 2014 11:39 AM To: r-help@r-project.org Subject: [R] Subsetting on multiple criteria (AND condition) in R I'm running the following to get what I

Re: [R] Subsetting on multiple criteria (AND condition) in R

2014-01-14 Thread Jeff Johnson
Thanks so much Marc and for those that responded. Mark's suggestion with droplevels gave me the desired result. I'm new to figuring out how to post reproducible code. I'll try using the set.seed and rnorm functions next time and hope that does the trick. Thanks everyone! On Tue, Jan 14, 2014

Re: [R] subsetting 3D array

2014-01-09 Thread arun
Hi Alex, Try: set.seed(345) results- array(sample(-5:5,120,replace=TRUE),dim=c(10,3,4)) indx - !!apply(results,1,sum) library(plyr) results2 - laply(lapply(seq(dim(results)[1]),function(i) results[i,,])[indx],identity) attr(results2,dimnames) - NULL  dim(results2) #[1] 9 3 4 A.K. I have a 3D

Re: [R] subsetting 3D array

2014-01-09 Thread Bert Gunter
Just use apply() and indexing instead! results[,,apply(results,3,sum)TRUE] ## will do it. However, note that numerical error may make a hash of this. So safer would be something like: eps - 1e-15 ## i.e. something small results[,,abs(apply(results,3,sum))eps] Cheers, Bert Bert Gunter

Re: [R] subsetting 3D array

2014-01-09 Thread arun
I figured it out: dim(results[apply(results,1,sum)TRUE,,]) #[1] 9 3 4 A.K. On , arun smartpink...@yahoo.com wrote: dim(results[,,apply(results,3,sum)TRUE]) #[1] 10  3  4 dim(results[,,abs(apply(results,3,sum))eps]) #[1] 10  3  4  dim(results2) #[1] 9 3 4 A.K. On Friday, January 10, 2014

Re: [R] Subsetting vector with preserved order

2014-01-02 Thread arun
Hi, Try ?match  b[match(d,a)] #[1] Joe  Bob  Dick A.K. I have three vectors as follows: a - c('A','B','C','D','E') b - c('Tom','Dick','Harry','Bob','Joe') d - c('E','D','B') Subsetting b by using d on a, with b[a %in% d], gives the names in the order they appear in b:  b[a %in% d]

Re: [R] Subsetting vector with preserved order

2014-01-02 Thread Hervé Pagès
Hi On 01/02/2014 04:04 PM, arun wrote: Hi, Try ?match b[match(d,a)] #[1] Joe Bob Dick Or use 'a' to put names on 'b': names(b) - a b A B C D E Tom Dick Harry Bob Joe Then subset by names: b[d] E D B Joe Bob Dick

Re: [R] Subsetting Timestamped data

2013-10-07 Thread MacQueen, Don
Here is an approach using base R tools (not tested, so I hope I don't embarrass myself!) dayid - format(data$TimeStamp, '%Y-%m-%d') day.counts - table(dayid) good.days - names(day.counts)[day.counts == 48] subset(data, dayid %in% good.days) This could be written in a one-liner, but it's much

[R] Subsetting Timestamped data

2013-10-04 Thread aj409
Hi, I have a data frame, data, containing two columns: one- the TimeStamp (formatted using data$TimeStamp - as.POSTIXct(as.character(data$TimeStamp), format = %d/%m/%Y %H:%M) ) and two- the data value. The data frame has been read from a .csv file and should contain 48 values for each

Re: [R] Subsetting Timestamped data

2013-10-04 Thread arun
[ddply(df1,.(as.Date(datetime)),mutate,Ldt=length(datetime)==48)$Ldt,]  identical(df3,df2) #[1] TRUE A.K. - Original Message - From: aj...@bath.ac.uk aj...@bath.ac.uk To: r-help@r-project.org Cc: Sent: Friday, October 4, 2013 11:03 AM Subject: [R] Subsetting Timestamped data Hi, I have

Re: [R] Subsetting isolating a group of values in a group of variables

2013-09-08 Thread arun
Hi Razi, Using dat1: dat1[apply(dat1[,2:4],1,function(x) any(x%in% vec1)),] #  ID diag1 diag2 diag3 proc1 proc2 proc3 #2  2   k69   i80  u456  z456  z123  z456 #3  3   l91  i801  g678  u456  u123  u123 #4  4   i80   i90  h983  z123  z456  z456 #similarly, if the columns are from 18:93, change

Re: [R] Subsetting isolating a group of values in a group of variables

2013-09-07 Thread arun
Hi, The expected output is not clear. dat1- read.table(text=ID diag1 diag2 diag3 proc1 proc2 proc3 1 k23 i269 j123   u123  u456  u123 2 k69 i80 u456   z456  z123  z456 3 l91 i801 g678   u456  u123  u123 4 i80 i90 h983   z123  z456   z456,sep=,header=TRUE,stringsAsFactors=FALSE) vec1-

  1   2   3   4   5   >