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

2022-07-01 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

Re: [R] Subsetting Data from a Dataframe

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

Re: [R] Subsetting Data from a Dataframe

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

Re: [R] subsetting 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"] [1]

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-27 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 creat

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

2018-07-27 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 my

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 would

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)) - 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] f

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]) { i

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 expected output > > R Datafr

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 Dataframe1:

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 basic subsetting/data wr

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 wrote: > Have

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 pos

Re: [R] Subsetting a square marix

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

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

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 would you want your su

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,] "1

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 v

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 lis

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 expl

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 grou

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 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 wrote: > Dear all, > > would appreciate y

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

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), 'dim(tmpdat)',dim(tmpdat),'\n

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

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 esplana

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 datafram

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 Sof

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 > > input[[

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 input[[67]]$content[[1]]

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 Lindber

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” th

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-19 Thread Charles Berry
Aron Lindberg 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/ raw/a78cbf873a7e865c3173f943ff6309ea688c653b/dput >

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 data with svyglm

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

Re: [R] Subsetting data with svyglm

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

Re: [R] Subsetting 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

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

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

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

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

Re: [R] subsetting 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 leng

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 neighbourin

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 wrote: Hi Monaly, May be this hel

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

2014-05-23 Thread arun
eb"), class = "data.frame", row.names = c(NA,  -99L)) #Code for  tessellation library(deldir) ao= read.table("C:/Users/Monaly/Desktop/2012_malenest.txt", header=TRUE) a29= deldir(ao$lat_xm, ao$long_ym) a30=tile.list(a29) plot(a30, close=TRUE, main="2012 Male Nest"

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

2014-05-23 Thread Monaly Mistry
"latitude (m)", ylab="longitude (m)", wpoints="real", verbose=FALSE,num=TRUE, rw=c(0, 1200, 0, 2000)) text(ao$lat_xm, ao$long_ym,col=c(2,1,4),labels=round(ao$NestkastNummer, 3), pos=2, offset=0.2, cex=0.7) #this was to identify the points On Fri, May 23, 2

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

2014-05-23 Thread Frede Aakmann Tøgersen
])-XO[1,c("176","140","133","163")])) > > > XO["avg", "15"]<- mean(abs((XO[1,"15"])-XO[1,c("16","19","14")])) > > > XO["avg", "60"]<- mean(abs((XO[1,"60&qu

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

2014-05-23 Thread Monaly Mistry
uot;,"97","90","84","82","81")])) > > XO["avg", "31"]<- mean(abs((XO[1,"31"])-XO[1,c("2","3","36","35","34")])) > > XO["avg", "73"]<- mean

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

2014-05-22 Thread Monaly Mistry
quot;64"]<- mean(abs((XO[1,"64"])-XO[1,c("113","62","128","124")])) > XO["avg", "74"]<- mean(abs((XO[1,"74"])-XO[1,c("51","73","185")])) > XO["avg", "95"]<

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

2014-05-22 Thread Monaly Mistry
XO["avg", "36"]<- mean(abs((XO[1,"36"])-XO[1,c("28","38","86","709","707","35","3")])) XO["avg", "80"]<- mean(abs((XO[1,"80"])-XO[1,c("42","79&quo

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 wrote: > Hi,

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 wrote: > Hi, > > It would be helpful if you provide a reproducible example using ?dput(). > >

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

2014-03-27 Thread Sneha Bishnoi
t; -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-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 Sara

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

2014-03-27 Thread David Carlson
e 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 problem completely. V provides choices for only certain set of columns in Finaldata. So v2 may not represent al

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 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 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

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 ad

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 wh

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 at

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

2014-01-14 Thread William Dunlap
Here is a reproducible example of your problem where you do not want to see a table entry for "Medium". > tmp_df <- data.frame(Size=factor(rep(c("Small","Medium","Large"),1:3), levels=c("Small","Medium","Large"))) > non_medium <- subset(tmp_df, Size != "Medium", select=Size) > table(non_medi

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 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 != "US", > sel

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 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(myd

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 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 12:56 AM, Bert Gunt

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 Gen

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

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

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

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 e

Re: [R] Subsetting Timestamped data

2013-10-04 Thread arun
Hi, May be this helps: set.seed(45) df1<- data.frame(datetime=as.POSIXct("2011-05-25",tz="GMT")+0:200*30*60,value=sample(1:40,201,replace=TRUE),value2= sample(45:90,201,replace=TRUE))  df2<- df1[ave(1:nrow(df1),as.Date(df1[,1]),FUN=length)==48,]  dim(df2) #[1] 192   3 #or library(plyr) df3<-df

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 ac

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

2013-09-07 Thread arun
Hi, Using the same example: str1<-paste(colnames(dat1)[grepl("diag",colnames(dat1))],"%in%","vec1",collapse="|")  subset(dat1,eval(parse(text=str1))) #  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

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<- c("i80

Re: [R] Subsetting multiple rows of a data frame at once

2013-07-05 Thread arun
row.names(carbon.fit),stringsAsFactors=FALSE) #changed here  res1<-merge(dat1,carbon.fit1,by=c("x","y"))  row.names(res1)<- res1[,3]  res1<- res1[,-3] A.K. - Original Message - From: William Dunlap To: arun ; Shaun ♥ Anika Cc: R help Sent: Thursday, July 4, 2013 8:0

Re: [R] Subsetting multiple rows of a data frame at once

2013-07-04 Thread William Dunlap
xt,y=yt), carbon.fit) (You still want to round your numbers as before.) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of arun > Sent: Wednesday, July 03, 201

Re: [R] Subsetting multiple rows of a data frame at once

2013-07-04 Thread arun
Hi, carbon.fit = expand.grid(list(x=seq(0, 5, 0.01), y=seq(0, 5, 0.01)))  dim(carbon.fit) #[1] 251001  2  xtNew<-sprintf("%.2f",xt)  ytNew<- sprintf("%.2f",yt)  carbon.fit[]<- lapply(carbon.fit,function(x) sprintf("%.2f",x)) res<-do.call(rbind,lapply(seq_along(xtNew),function(i) subset(carb

Re: [R] Subsetting multiple rows of a data frame at once

2013-07-04 Thread arun
Hi, Possibly, FAQ 7.31 Using the same example: set.seed(24) df<- data.frame(x=sample(seq(0.25,4.25,by=.05),1e5,replace=TRUE),y= sample(seq(0.10,1.05,by=.05),1e5,replace=TRUE),z=rnorm(1e5)) dfOld<- df  df[,1:2]<- lapply(df[,1:2],function(x) sprintf("%.2f",x)) x1<- c(1.05,2.85,3.40,4.25,0.25) y1<-

Re: [R] Subsetting multiple rows of a data frame at once

2013-07-03 Thread arun
Hi, Try this: set.seed(24) df<- data.frame(x=sample(seq(0.25,4.25,by=.05),1e5,replace=TRUE),y= sample(seq(0.10,1.05,by=.05),1e5,replace=TRUE),z=rnorm(1e5)) #Used a shorter vector x1<- c(1.05,2.85,3.40,4.25,0.25) y1<- c(0.25,0.10,0.90,0.25,1.05) res<-do.call(rbind,lapply(seq_along(x1),function

Re: [R] Subsetting out missing values for a certain variable

2013-06-05 Thread Jorge I Velez
Daniel, You need "==" instead of "=". HTH, Jorge.- Sent from my phone. Please excuse my brevity and misspelling. On Jun 6, 2013, at 10:36 AM, Daniel Tucker wrote: > Also tried this but results werent any different > > subset1<- subset(dframe, glb_ind="Y" | sample==1 | !is.na(glb_ind)) > subset2

Re: [R] Subsetting out missing values for a certain variable

2013-06-05 Thread Daniel Tucker
Also tried this but results werent any different subset1<- subset(dframe, glb_ind="Y" | sample==1 | !is.na(glb_ind)) subset2<-subset(dframe, cwar_ind="Y" |sample==2 | !is.na(cwar_ind)) subset3<-subset(dframe, reg_ind="Y" | sample==3 | !is.na(reg_ind)) On Wed, Jun 5, 2013 at 9:33 AM, Daniel Tucke

Re: [R] Subsetting out missing values for a certain variable

2013-06-05 Thread Daniel Tucker
The problem might be that "NAs" in the dataset are blank On Wed, Jun 5, 2013 at 9:54 AM, Daniel Tucker wrote: > Also tried this but results werent any different > > subset1<- subset(dframe, glb_ind="Y" | sample==1 | !is.na(glb_ind)) > subset2<-subset(dframe, cwar_ind="Y" |sample==2 | !is.na(cwar

Re: [R] subsetting and Dates

2013-05-23 Thread David Winsemius
http://r.789695.n4.nabble.com/as-vector-with-mode-quot-list-quot-and-POSIXct-td4667533.html Interesting but I fail to see the connection to this instance other than R behaving somewhat differently than we might at one time have expected. -- David. > > A.K. > > - Original Mess

Re: [R] subsetting and Dates

2013-05-23 Thread arun
. - Original Message - From: Denis Chabot To: arun Cc: R help Sent: Thursday, May 23, 2013 10:06 PM Subject: Re: [R] subsetting and Dates Thank you for the 2 methods to make the columns class Date, but I would really like to know why these variables were not in Date class with my code

Re: [R] subsetting and Dates

2013-05-23 Thread David Winsemius
On May 23, 2013, at 7:06 PM, Denis Chabot wrote: > Thank you for the 2 methods to make the columns class Date, but I would > really like to know why these variables were not in Date class with my code. > Do you know? I suspect that the problem lies in the dispatch to `[<-.` or `$<-`. When the

Re: [R] subsetting and Dates

2013-05-23 Thread Denis Chabot
Thank you for the 2 methods to make the columns class Date, but I would really like to know why these variables were not in Date class with my code. Do you know? Denis Le 2013-05-23 à 21:44, arun a écrit : > You could convert those columns to "Date" class by: > > > Data[,c(4,6)]<-lapply(Da

Re: [R] subsetting and Dates

2013-05-23 Thread arun
You could convert those columns to "Date" class by: Data[,c(4,6)]<-lapply(Data[,c(4,6)],as.Date,origin="1970-01-01") #or Data[,c(4,6)]<-lapply(Data[,c(4,6)],function(x) structure(x,class="Date")) #  dat1  dat2  Dat1a  Dat1b  Dat2a  Dat2b #1  41327 41327 2013-02-22 2013-02-22 201

Re: [R] subsetting by is not

2013-05-09 Thread Sarah Goslee
Without a reproducible example it's hard to say for certain, but I imagine you want buybdge != badge or !(buybdge == badge) Note that ?"==" (the help for == ) would have told you that. Sarah On Thu, May 9, 2013 at 4:05 PM, ramoss wrote: > Hello, > > I have a simple question: > > I know how to s

Re: [R] subsetting by is not

2013-05-09 Thread ramoss
I want to clarify we are talking about 2 variables in a datframe here. -- View this message in context: http://r.789695.n4.nabble.com/subsetting-by-is-not-tp4666706p4666707.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-pro

Re: [R] subsetting dataframe multiple conditions

2013-05-09 Thread Rui Barradas
Hello, Em 09-05-2013 20:44, Sarah Goslee escreveu: Hi, On Thu, May 9, 2013 at 12:28 PM, KatrinH Heimann wrote: Dear all, I would like to subset a dataframe using multiple conditions. So if I have two columns 1 and 2, I would like to EXCLUDE all rows in which the value of column 1 is "a" AND t

Re: [R] subsetting dataframe multiple conditions

2013-05-09 Thread Rui Barradas
Hello, It's difficult to know what's going on without a data example. Can you post the output of dput(head(data, 30)) ? Maybe the columns are not of class "character" but of class "factor". You should also post the output of str(data) In the mean time, try subset(data, column1 != "a" &

Re: [R] subsetting dataframe multiple conditions

2013-05-09 Thread Sarah Goslee
Hi, On Thu, May 9, 2013 at 12:28 PM, KatrinH Heimann wrote: > Dear all, > I would like to subset a dataframe using multiple conditions. > So if I have two columns 1 and 2, I would like to EXCLUDE all rows in which > the value of column 1 is "a" AND the value of column 2 is "b". > I tried data[(da

Re: [R] Subsetting a large number into smaller numbers and find the largest product

2013-04-18 Thread arun
Hi Janesh, This is a bit shorter: library(seqinr) sapply(split(as.numeric(s2c(x)),((seq(nchar(x))-1)%/%5)+1),prod)   A.K. - Original Message - From: arun To: Janesh Devkota Cc: R help Sent: Thursday, April 18, 2013 8:55 AM Subject: Re: [R] Subsetting a large number into smaller

Re: [R] Subsetting a large number into smaller numbers and find the largest product

2013-04-18 Thread arun
Hi, You could also use: x <- "73167176531330624919225119674426574742355349194934969835203127745063262395783180169848018694788518438586156078911294949545950173795833195285320880551112540698747158523863050715693290963295227443043557"   sapply(strsplit(substring(x,seq(1,nchar(x)-4,5),seq(5,nchar(x),5

Re: [R] Subsetting a large number into smaller numbers and find the largest product

2013-04-18 Thread andrija djurovic
Hi. Here is one approach: options(scipen=300) numb <- 73167176531330624919225119674426574742355349194934969835203127745063262395783180169848018694788518438586156078911294949545950173795833195285320880551112540698747158523863050715693290963295227443043557 strsplit(as.character(numb), "") blocks <-

Re: [R] Subsetting a large number into smaller numbers and find the largest product

2013-04-18 Thread Jorge I Velez
Dear Janesh, Here is one way: # note "x" is a character x <- "73167176531330624919225119674426574742355349194934969835203127745063262395783180169848018694788518438586156078911294949545950173795833195285320880551112540698747158523863050715693290963295227443043557" k <- nchar(x) # digits in x b <

  1   2   3   4   >