Re: [R] Select dataframe row containing a digit

2022-12-01 Thread Luigi Marongiu
Thank you, those are all viable solutions. Regards Luigi On Wed, Nov 30, 2022 at 8:59 PM Rolf Turner wrote: > > > On Wed, 30 Nov 2022 13:40:50 +0100 > Luigi Marongiu wrote: > > > Hello, > > I have a data frame where some lines containing strings including > > digits. How do I select those rows a

Re: [R] Select dataframe row containing a digit

2022-11-30 Thread Rolf Turner
On Wed, 30 Nov 2022 13:40:50 +0100 Luigi Marongiu wrote: > Hello, > I have a data frame where some lines containing strings including > digits. How do I select those rows and change their values? > > In essence, I have a data frame with different values assigned to the > column "val". I am for

Re: [R] Select dataframe row containing a digit

2022-11-30 Thread Bert Gunter
I just noticed that I forgot about the "" <-> NA clause. So my "onego" solution should be: df <- ## to assign back to df or perhaps a new frame within(df, val <- ifelse(val == "", NA, ifelse(grepl("P|Y", val, ignore.case = TRUE), "POS", ifelse(grepl("N", val, ignore.case = TR

Re: [R] Select dataframe row containing a digit

2022-11-30 Thread Bert Gunter
... or, if you wanted to do it all in one go: within(df, val <- ifelse(grepl("P|Y", val, ignore.case = TRUE), "POS", ifelse(grepl("N", val, ignore.case = TRUE), "NEG","NUM"))) ## which gives [1] "NUM" "POS" "POS" "POS" "POS" "NUM" "NEG" "NEG" "NUM" "NUM" for the "val" column

Re: [R] Select dataframe row containing a digit

2022-11-30 Thread Rui Barradas
Às 12:40 de 30/11/2022, Luigi Marongiu escreveu: Hello, I have a data frame where some lines containing strings including digits. How do I select those rows and change their values? In essence, I have a data frame with different values assigned to the column "val". I am formatting everything to

Re: [R] Select dataframe row containing a digit

2022-11-30 Thread Michael Dewey
I suspect [[:digit:]] might have done what you want. Michael On 30/11/2022 13:04, Luigi Marongiu wrote: Thank you, I have been trying with [:digit:] but did not work. It worked with `df$val[grepl('[0-9]', df$val)] = "NUM"` On Wed, Nov 30, 2022 at 2:02 PM Ivan Krylov wrote: В Wed, 30 Nov 202

Re: [R] Select dataframe row containing a digit

2022-11-30 Thread Luigi Marongiu
Thank you, I have been trying with [:digit:] but did not work. It worked with `df$val[grepl('[0-9]', df$val)] = "NUM"` On Wed, Nov 30, 2022 at 2:02 PM Ivan Krylov wrote: > > В Wed, 30 Nov 2022 13:40:50 +0100 > Luigi Marongiu пишет: > > > I am formatting everything to either "POS" and "NEG", > >

Re: [R] Select dataframe row containing a digit

2022-11-30 Thread Ivan Krylov
В Wed, 30 Nov 2022 13:40:50 +0100 Luigi Marongiu пишет: > I am formatting everything to either "POS" and "NEG", > but values entered as number should get the value "NUM". > How do I change such values? Thanks for providing an example! One idea would be to use a regular expression to locate numb

[R] Select dataframe row containing a digit

2022-11-30 Thread Luigi Marongiu
Hello, I have a data frame where some lines containing strings including digits. How do I select those rows and change their values? In essence, I have a data frame with different values assigned to the column "val". I am formatting everything to either "POS" and "NEG", but values entered as numbe

Re: [R] select() columns using their positions

2020-08-20 Thread Rui Barradas
Hello, It is also possible to select by vectors of indices (as opposed to a vector): top_n is just to not clutter the display. library(dplyr) data(iris) iris %>% select(1, 3, 4) %>% top_n(5) iris %>% select(c(1, 3), 4) %>% top_n(5) Hope this helps, Rui Barradas Às 10:05 de 20/08/20, Iv

Re: [R] select() columns using their positions

2020-08-20 Thread Ivan Calandra
OK, my bad... I'm sure I had tried it and it didn't work, but I guess the error was somewhere else... Thank you! Ivan -- Dr. Ivan Calandra TraCEr, laboratory for Traceology and Controlled Experiments MONREPOS Archaeological Research Centre and Museum for Human Behavioural Evolution Schloss Monrep

Re: [R] select() columns using their positions

2020-08-20 Thread Jeff Newmiller
Did you try it? mydata %>%   select( c( 1, 2, 4 ) ) On August 20, 2020 1:41:13 AM PDT, Ivan Calandra wrote: >Dear useRs, > >I'm still trying to learn tidyverse syntax. > >I would like to select() columns based on their positions/indices, but >I >cannot find a way to do that (I've seen a lot abou

[R] select() columns using their positions

2020-08-20 Thread Ivan Calandra
Dear useRs, I'm still trying to learn tidyverse syntax. I would like to select() columns based on their positions/indices, but I cannot find a way to do that (I've seen a lot about doing that for rows, but I could not find anything for columns). I thought it would be obvious, but I cannot find it

Re: [R] Select

2019-02-11 Thread Val
;>>> grp <- rep(mydat$group, mydat$count) > >>>>> grp.sam <- sample(grp, 40) > >>>>> table(grp.sam) > >>>> grp.sam > >>>> G1 G2 G3 G4 G5 > >>>> 10 9 5 13 3 > >>>> > >>>> -

Re: [R] Select

2019-02-11 Thread Jeff Newmiller
avid L Carlson Department of Anthropology Texas A&M University College Station, TX 77843-4352 -Original Message- From: R-help On Behalf Of Val Sent: Monday, February 11, 2019 4:36 PM To: r-help@R-project.org (r-help@r-project.org) Subject: [R] Select Hi all, I have a data frame w

Re: [R] Select

2019-02-11 Thread Val
gt; >> Texas A&M University > >> College Station, TX 77843-4352 > >> > >> > >> -Original Message- > >> From: R-help On Behalf Of Val > >> Sent: Monday, February 11, 2019 4:36 PM > >> To: r-help@R-project.org (r-help@r-proje

Re: [R] Select

2019-02-11 Thread Göran Broström
On 2019-02-11 23:35, Val wrote: Hi all, I have a data frame with tow variables group and its size. mydat<- read.table( text='group count G1 25 G2 15 G3 12 G4 31 G5 10' , header = TRUE, as.is = TRUE ) How about x <- sample(1:5) total <- mydat$count[x[1]] i <- 1 while (total < 40){

Re: [R] Select

2019-02-11 Thread Jeff Newmiller
pology >> Texas A&M University >> College Station, TX 77843-4352 >> >> >> -Original Message- >> From: R-help On Behalf Of Val >> Sent: Monday, February 11, 2019 4:36 PM >> To: r-help@R-project.org (r-help@r-project.org) > >> Subjec

Re: [R] Select

2019-02-11 Thread Val
on > Department of Anthropology > Texas A&M University > College Station, TX 77843-4352 > > > -Original Message- > From: R-help On Behalf Of Val > Sent: Monday, February 11, 2019 4:36 PM > To: r-help@R-project.org (r-help@r-project.org) > Subject: [R] Sel

Re: [R] Select

2019-02-11 Thread David L Carlson
10 9 5 13 3 David L Carlson Department of Anthropology Texas A&M University College Station, TX 77843-4352 -Original Message- From: R-help On Behalf Of Val Sent: Monday, February 11, 2019 4:36 PM To: r-help@R-project.org (r-help@r-project.org) Subject: [R]

[R] Select

2019-02-11 Thread Val
Hi all, I have a data frame with tow variables group and its size. mydat<- read.table( text='group count G1 25 G2 15 G3 12 G4 31 G5 10' , header = TRUE, as.is = TRUE ) I want to select group ID randomly (without replacement) until the sum of count reaches 40. So, in the first case, the da

[R] Select behavior dependant with other factors and its formalization

2018-12-04 Thread Fatma Ell
Hi, I'm studying occurence of Behavior11, Behavior12,Behavior2,Behavior3 according three variables : Times : task time Time_interval :task time in interval Frequency:Frequency of the task For this purpose, I use GLM attach(datas) an11=anova(glm(Behavior11 ~ Times + Frequency, family=bino

Re: [R] select and hold missing

2018-09-12 Thread Bert Gunter
"Why it is setting all row values NA?" Because the row index is NA. e.g. > z <- data.frame(a=letters[1:3],b = 1:3); x <- c(TRUE,NA,FALSE) > z[x,] a b 1 a 1 NA NA Change your logical comparison to (using with() to simplify entry): > dfc[with(dfc, diff > 0 & diff < 100 | is.na(diff)

[R] select and hold missing

2018-09-12 Thread Val
I have a data dfc <- read.table( text= 'week v1 v2 w1 11 11 w1 .42 w1 31 32 w2 31 52 w2 41 . w3 51 82 w2 11 22 w3 11 12 w4 21 202 w1 31 72 w2 71 52', header = TRUE, as.is = TRUE, na.strings=c("",".","NA") ) I want to create this new variable diff = v2

Re: [R] Select part of character row name in a data frame

2017-10-20 Thread Francesca PANCOTTO
I did not need to select the whole character sentence, otherwise I would know how to do it.. from basic introduction to R as you suggest. Grep works perfectly. f. -- Francesca Pancotto, PhD > Il giorno 19 ott 2017, alle ore 18:01, Jeff Newmiller > ha scritto: >

Re: [R] Select part of character row name in a data frame

2017-10-19 Thread Jeff Newmiller
(Re-)read the discussion of indexing (both `[` and `[[`) and be sure to get clear on the difference between matrices and data frames in the Introduction to R document that comes with R. There are many ways to create numeric vectors, character vectors, and logical vectors that can then be used as

Re: [R] Select part of character row name in a data frame

2017-10-19 Thread Francesca PANCOTTO
Thanks a lot, so simple so efficient! I will study more the grep command I did not know. Thanks! Francesca Pancotto > Il giorno 19 ott 2017, alle ore 12:12, Enrico Schumann > ha scritto: > > df[grep("strat", row.names(df)), ] [[alternative HTML version deleted]]

Re: [R] Select part of character row name in a data frame

2017-10-19 Thread Enrico Schumann
Quoting Francesca PANCOTTO : Dear R contributors, I have a problem in selecting in an efficient way, rows of a data frame according to a condition, which is a part of a row name of the table. The data frame is made of 64 rows and 2 columns, but the row names are very long but I need to s

[R] Select part of character row name in a data frame

2017-10-19 Thread Francesca PANCOTTO
Dear R contributors, I have a problem in selecting in an efficient way, rows of a data frame according to a condition, which is a part of a row name of the table. The data frame is made of 64 rows and 2 columns, but the row names are very long but I need to select them according to a small part

Re: [R] select from data frame

2017-07-16 Thread Andras Farkas via R-help
thank you David and Bert, these solutions will work for me... Andras  On Saturday, July 15, 2017 6:05 PM, Bert Gunter wrote: ... and here is a slightly cleaner and more transparent way of doing the same thing (setdiff() does the matching) > with(df, setdiff(ID,ID[samples %in% c("B","C"

Re: [R] select from data frame

2017-07-15 Thread Bert Gunter
... and here is a slightly cleaner and more transparent way of doing the same thing (setdiff() does the matching) > with(df, setdiff(ID,ID[samples %in% c("B","C") ])) [1] 3 -- Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it."

Re: [R] select from data frame

2017-07-15 Thread Bert Gunter
If I understand correctly, no looping (ave(), for()) or type casting (as.character()) is needed -- indexing and matching suffice: > with(df, ID[!ID %in% unique(ID[samples %in% c("B","C") ])]) [1] 3 3 Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming a

Re: [R] select from data frame

2017-07-15 Thread David Winsemius
> On Jul 15, 2017, at 4:01 AM, Andras Farkas via R-help > wrote: > > Dear All, > > wonder if you could please assist with the following > > df<-data.frame(ID=c(1,1,1,2,2,3,3,4,4,5,5),samples=c("A","B","C","A","C","A","D","C","B","A","C")) > > from this data frame the goal is to extract the

[R] select from data frame

2017-07-15 Thread Andras Farkas via R-help
Dear All, wonder if you could please assist with the following df<-data.frame(ID=c(1,1,1,2,2,3,3,4,4,5,5),samples=c("A","B","C","A","C","A","D","C","B","A","C")) from this data frame the goal is to extract the value of 3 from the ID column based on the logic that the ID=3 in the data frame has

Re: [R] select a subset of a matrix which one of its column meet a condition

2015-07-08 Thread Rui Barradas
Hello, Your matrix has only 4 columns but you refer to met[,5]. I'll assume you're refering to the last column, met[,4]. Try reading the help page for ?%in%, it doesn't do what you seem to think it does. And try using <=. maf <- met[0 <= met[, 4] & met[, 4] <= 0.05, ] Hope this helps, Rui B

[R] select a subset of a matrix which one of its column meet a condition

2015-07-08 Thread Lida Zeighami
Hi there, I have a matrix and I want to get a subset from that which one of its matrix meet a condition, my matrix is met Row.names Name maf caf 1 10:13915 10:139 0.0003782148 0.0003782148 2 10:18738 10:1873

Re: [R] select portion of text file using R

2015-04-28 Thread Duncan Mackay
similar to above for the different sections I suggest you read up on regular expressions - I use them every day in various ways. ? sub and follow the prompts as well as the page Duncan -Original Message----- From: Luigi Marongiu [mailto:marongiu.lu...@gmail.com] Sent: Wednesday, 29 April

Re: [R] select portion of text file using R

2015-04-27 Thread Duncan Mackay
quot;,"Rn") dat = datc for (j in c(1,2,4,5)) dat[,j] = as.numeric(dat[,j]) Regards Duncan Duncan Mackay Department of Agronomy and Soil Science University of New England Armidale NSW 2351 Email: home: mac...@northnet.com.au -Original Message- From: R-help [mailto:r-help-boun...@r-pr

Re: [R] select portion of text file using R

2015-04-27 Thread jim holtman
try this. It read in all the data and discards the lines not required. > # read in the data and delete lines not required > data_in <- readLines(textConnection("HEAD OF MYDATA + * Block Type = Array Card Block + * Calibration Background is expired = No + * Calibration Background performed on =

Re: [R] select portion of text file using R

2015-04-27 Thread Duncan Murdoch
On 27/04/2015 5:20 PM, Luigi Marongiu wrote: > Dear Duncan, > thank you for your reply, > I tried to read the file using skip and nrows but it did not work. What does that mean? We might be able to be more help if you tell us what happened when you tried the code below. > Here i am pasting the c

Re: [R] select portion of text file using R

2015-04-27 Thread Luigi Marongiu
Dear Duncan, thank you for your reply, I tried to read the file using skip and nrows but it did not work. Here i am pasting the code I wrote and the head of the file i need to read. Probably the error is due to the fact that the column "well" has duplication, but how can i add a row column with uni

Re: [R] select portion of text file using R

2015-04-20 Thread Duncan Murdoch
On 20/04/2015 3:28 AM, Luigi Marongiu wrote: > Dear all, > I have a flat file (tab delimited) derived from an excel file which is > subdivided in different parts: a first part is reporting metadata, > then there is a first spreadsheet indicated by [ ], then the actual > data and the second spreadsh

[R] select portion of text file using R

2015-04-20 Thread Luigi Marongiu
Dear all, I have a flat file (tab delimited) derived from an excel file which is subdivided in different parts: a first part is reporting metadata, then there is a first spreadsheet indicated by [ ], then the actual data and the second spreadsheet with the same format [ ] and then the data. How can

[R] Select best maximum likelihood tree with raxml (package ips)

2015-01-07 Thread Luigi Marongiu
Dear all, I am trying to build a maximum likelihood (ML) tree using the raxml function of the package ips. I implemented the following script: tr<-raxml(seq.align,exec = "/usr/bin/raxmlHPC",b = 100, N = 10) where tr is the resulting tree, seq.align is the DNA alignment created wi

Re: [R] Select subtree with vector of leaves using zoom function of the ape package

2015-01-02 Thread Ben Bolker
Luigi Marongiu gmail.com> writes: > I am drawing a phylogenetic tree using the zoom() function of the > ape package. Since I have 476 sequences in my alignment, this allows > me to have the outlook of the main tree and then highlight a portion > of it, and this works fine. At the moment I am us

[R] Select subtree with vector of leaves using zoom function of the ape package

2015-01-01 Thread Luigi Marongiu
Dear all, I am drawing a phylogenetic tree using the zoom() function of the ape package. Since I have 476 sequences in my alignment, this allows me to have the outlook of the main tree and then highlight a portion of it, and this works fine. At the moment I am using the approach of indicating th

Re: [R] select same row in a data frame several times

2014-11-14 Thread MacQueen, Don
Sorry, I was too quick. Try A[ match(B, A$ID2) ,] -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 11/14/14, 1:45 PM, "Pedro Mardones" wrote: >Dear R user; > >Consider the following toy example > >A <- data.frame(ID1 = c(1

Re: [R] select same row in a data frame several times

2014-11-14 Thread Rolf Turner
On 15/11/14 10:45, Pedro Mardones wrote: Dear R user; Consider the following toy example A <- data.frame(ID1 = c(1,2,3,1,2,3,1,2,3), ID2 = c("a","b","c","d","e","f","g","h","i"), stringsAsFactors = FALSE) B <- sample(a$ID2, 6, replace = TRUE) Lets say B is = "a", "a", "a", "h", "b", "e" I wan

Re: [R] select same row in a data frame several times

2014-11-14 Thread MacQueen, Don
Try B <- c("a", "a", "a", "h", "b", "e") subset(A, ID2 %in% B) or subset(A, ID2 %in% unique(B)) will do as well -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 11/14/14, 1:45 PM, "Pedro Mardones" wrote: >Dear R user; >

[R] select same row in a data frame several times

2014-11-14 Thread Pedro Mardones
Dear R user; Consider the following toy example A <- data.frame(ID1 = c(1,2,3,1,2,3,1,2,3), ID2 = c("a","b","c","d","e","f","g","h","i"), stringsAsFactors = FALSE) B <- sample(a$ID2, 6, replace = TRUE) Lets say B is = "a", "a", "a", "h", "b", "e" I want to extract from A the rows where ID2 == B

Re: [R] select randomly from a list

2014-05-22 Thread Boris Steipe
You are probably encountering an annoying behaviour of sample(): when it is given exactly one integer as an argument, it takes this as the upper limit of a range. a <- c(3,5) sample(a,10, replace=TRUE) #[1] 5 5 3 3 3 3 3 3 3 5 a <- c(5) sample(a,10, replace=TRUE) #[1] 2 1 3 1 1 3 4 5 1 4 #i.e

Re: [R] select randomly from a list

2014-05-22 Thread peter dalgaard
It's a well known quirk of sample that it changes behavior when the x argument has length 1: > replicate(10,sample(4:5, 1)) [1] 5 4 5 4 5 4 5 4 4 4 > replicate(10,sample(5:5, 1)) [1] 5 3 1 1 1 2 5 3 2 2 One workaround is to zap the offending branch inside sample: > Sample <- function (x, size

Re: [R] select randomly from a list

2014-05-22 Thread Jim Lemon
On Thu, 22 May 2014 09:54:13 AM Ragia Ibrahim wrote: > Hi, > kindly I want to select randomly and item from list of items. the list > generated in a looping process. I used sample(mylist,1) it works fine. > BUTsome times the list have only one item. that should be chosen in this > case since there

Re: [R] select randomly from a list

2014-05-22 Thread arun
Hi, I am not sure I understand the problem.  Please provide a reproducible example using ?dput(). mylist <- list(1:3, LETTERS[1:2], rnorm(4)) sample(mylist,1) sample(mylist,1)  mylist1 <- list(1:2) sample(mylist1,1) #[[1]] #[1] 1 2  sample(mylist1,1) #[[1]] #[1] 1 2 A.K. On Thursday, May

[R] select randomly from a list

2014-05-22 Thread Ragia Ibrahim
Hi, kindly I want to select randomly and item from list of items. the list generated in a looping process. I used sample(mylist,1) it works fine. BUTsome times the list have only one item. that should be chosen in this case since there is no other one. I found that sample return different item n

Re: [R] select maximum values

2014-03-31 Thread Sébastien Durier
hello, It's also possible to use the quantile function : vec0 <- c(0.1,0.2, 0.5, 0.1,0.8, 0.4, 0.9) which(vec0 >= quantile(vec0, 0.7, type = 1)) SD 2014-03-29 18:02 GMT+01:00 arun : > Hi, > Try: > vec1 <- setNames(c(0.1,0.2, 0.5, 0.1,0.8, 0.4, 0.9), 1:7) > vec2 <- sort(vec1,decreasing=TRUE) >

Re: [R] select maximum values

2014-03-29 Thread arun
Hi, Try: vec1 <- setNames(c(0.1,0.2, 0.5, 0.1,0.8, 0.4, 0.9), 1:7) vec2 <- sort(vec1,decreasing=TRUE) names(vec2[seq(ceiling(length(vec2)*0.3))]) #[1] "7" "5" "3"  A.K. Hi, I need your help again. I have some data like this: 1 23 4 56 7 ... 0.1 0.2 0.5

Re: [R] Select random observation from a group

2014-03-27 Thread arun
Hi, May be this helps: set.seed(42) indx <- with(df,tapply(seq_along(IndividualID), FamilyID,FUN=sample,1))  df[indx,] # FamilyID IndividualID DadID MomID Sex #4    1  104 0 0   2 #8    2  204   202   203   2 #or library(plyr)  ddply(df,.(FamilyID),function(x) x[w

Re: [R] Select random observation from a group

2014-03-27 Thread Peter Alspach
2014 10:11 a.m. To: r-help@r-project.org Subject: [R] Select random observation from a group Hello, I have a dataset with family data. For an analysis, I need to select one subject per family at random. Here is an example of what my data look like: FamilyID IndividualID DadID

[R] Select random observation from a group

2014-03-27 Thread Whitney Melroy
Hello, I have a dataset with family data. For an analysis, I need to select one subject per family at random. Here is an example of what my data look like: FamilyID IndividualID DadIDMomID Sex 1101103 104 1 1

Re: [R] select groups

2014-02-11 Thread arun
Hi, Try: row.names(res) <- gsub(".*\\.","",row.names(res))  row.names(res)[1:2] #[1] "23" "2" A.K. Thank you very much. But it's possible have the inicial number of the row without a.23, but only 23, for example? It's important to know which row I had select. Thank you very much for yo

Re: [R] select groups

2014-02-11 Thread arun
Hi, Try: set.seed(42)  dat <-as.data.frame(matrix(sample(20:100,4*45,replace=TRUE),ncol=4)) set.seed(345)  dat <- within(dat,class1 <- sample(letters[1:3],45,replace=TRUE) )  table(dat$class1)*0.4 # #  a   b   c #6.0 4.8 7.2 set.seed(85) res <- do.call(rbind,lapply(split(dat,dat$class1),function

Re: [R] Select 5 identical numbers

2014-01-20 Thread Daniel Nordlund
read up on ?sample Dan Daniel Nordlund Bothell, WA USA > -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf Of Alaios > Sent: Monday, January 20, 2014 10:12 PM > To: Alaios; R-help@r-project.org > Subject

Re: [R] Select 5 identical numbers

2014-01-20 Thread Alaios
Hi, I want from a vector containing has like 1000 elements to select X of it randomly but with never selecting the same element again. Each one should be unique element of the vector. Is this more precise now? Regards Alex On Monday, January 20, 2014 7:54 PM, Alaios wrote: Dear all, I wou

Re: [R] Select 5 identical numbers

2014-01-20 Thread Bert Gunter
But just noting the usual floating point stuff, Jim's approach might run into problems depending on what you have as "numbers" and what is meant by "identical." Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 "Data is not information. Information is not knowledge. And

Re: [R] Select 5 identical numbers

2014-01-20 Thread jim holtman
Use 'table' to count the occurances and then select the one that has a count of 5. Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. On Mon, Jan 20, 2014 at 12:07 PM, Alaios wrote: > Dear all, > I would like t

[R] Select 5 identical numbers

2014-01-20 Thread Alaios
Dear all, I would like to select from a vector of 10 elements, 5 of those that are identical. How can I do that in R? I guess one way would be to taking random numbers and see if that appeared again. Is though there a more straightforward approach? Regards Alex [[alternative HTML version

Re: [R] Select rows of a data frame according to values of vector in a list

2014-01-03 Thread Mohammad Tanvir Ahamed
Thanks !!   Best regards ...  Tanvir Ahamed Göteborg, Sweden From: Rui Barradas -h...@r-project.org> Sent: Friday, 3 January 2014, 10:58 Subject: Re: [R] Select rows of a data frame according to values of vector in a list He

Re: [R] Select rows of a data frame according to values of vector in a list

2014-01-03 Thread Rui Barradas
Hello, Try the following. lapply(lis, function(i) df[i, ]) Hope this helps, Rui Barradas Em 03-01-2014 09:04, Mohammad Tanvir Ahamed escreveu: Hi there !! I have a list like as follows : lis $lis1 [1] 1 3 5 $lis2 [1] 2 4 6 8 9 I have another data frame like as follows df 1 10 110 2 1

[R] Select rows of a data frame according to values of vector in a list

2014-01-03 Thread Mohammad Tanvir Ahamed
Hi there !! I have a list like as follows :  >lis $lis1 [1] 1 3 5  $lis2 [1] 2 4 6 8 9 I have another data frame like as follows  >df 1 10 110 2 15 120 3 20 130 4 25 140 5 30 150 6 35 160 7 40 150 8 45 180 9 50 190 Now i want to select the rows of data frame by the value of list and the output

Re: [R] select .txt from .txt in a directory

2013-11-11 Thread Zilefac Elvis
Thanks, AK. The three codes worked as expected. Again, thanks so much for understanding my problem and proving the right solutions. Atem. On Saturday, November 9, 2013 6:27 PM, arun wrote: HI, The code could be shortened by using ?merge or ?join(). library(plyr) ##Using the output from `lst

Re: [R] select .txt from .txt in a directory

2013-11-09 Thread arun
HI, The code could be shortened by using ?merge or ?join(). library(plyr) ##Using the output from `lst6` lst7 <- lapply(lst6,function(x) {x1 <- data.frame(Year=rep(1961:2005,each=12),Mo=rep(1:12,45)); x2 <-join(x1,x,type="left",by=c("Year","Mo"))}) ##rest are the same (only change in object n

Re: [R] select .txt from .txt in a directory

2013-11-09 Thread arun
Hi, Try: library(stringr) # Created the selected files (98) in a separate working  folder (SubsetFiles1) (refer to my previous mail) filelst <- list.files() #Sublst <- filelst[1:2] res <- lapply(filelst,function(x) {con <- file(x)      Lines1 <- readLines(con) close(con)      Lines2 <- Lines

Re: [R] select .txt from .txt in a directory

2013-11-08 Thread arun
Hi Atem, It is not clear what you wanted to do.  If you want to transfer the subset of files from the main folder to a new location, then you may try: (make sure you create a copy of the original .txt folder before doing this) I created three sub folders and two files (BTemperature_Stations.tx

Re: [R] select .txt from .txt in a directory

2013-11-08 Thread Simon Zehnder
Elvis, first, keep things on the list - so others can learn and comment. Second, as Sarah already commented: We do not like to open unsolicited binary attachments on the list. Sarah gives a good hint how to post data to the list. What I would do so far is use the matching columns to get the nam

Re: [R] select .txt from .txt in a directory

2013-11-08 Thread Simon Zehnder
If you want to type in the names by hand, you can simply use read.table to load them into R … I still don’t get the aim of your text file handling On 08 Nov 2013, at 18:51, Zilefac Elvis wrote: > All files are text files. They are found in a folder on my computer. > Assume that I know the nam

Re: [R] select .txt from .txt in a directory

2013-11-08 Thread Zilefac Elvis
All files are text files. They are found in a folder on my computer.  Assume that I know the names of some of the files I want to select from the 300 txt files. How can I do this in R. Atem. On Friday, November 8, 2013 11:44 AM, Simon Zehnder wrote: I do not understand the question. If you

Re: [R] select .txt from .txt in a directory

2013-11-08 Thread Bert Gunter
1. Please don't post in HTML (see posting guide). 2. What do you mean by "extract?" 3. Your qiestion sounds very basic. Have you read "An Introduction to R" or other online R tutorial? If not please do so before posting further. All of R's file input functions allow you to specify the directory p

Re: [R] select .txt from .txt in a directory

2013-11-08 Thread Simon Zehnder
I do not understand the question. If you already know the names what is the problem to select the files by names? If you have the names but not inside of R you have to find a name pattern to avoid typing them in. Is there a pattern, e.g. da.txt, db.txt, dc.txt? On 08 Nov 2013, at 18:33, Zile

Re: [R] select .txt from .txt in a directory

2013-11-08 Thread Sarah Goslee
How do you decide which ones you need? Is there some pattern that lets you distinguish needing df.txt from not needing ds.txt? You say you "have the names" - how do you have them? In a text file? What are you trying to do with the text files? Sarah On Fri, Nov 8, 2013 at 12:33 PM, Zilefac Elvi

[R] select .txt from .txt in a directory

2013-11-08 Thread Zilefac Elvis
Hi, I have 300 .txt files in a directory. Out of this 300, I need just 100 of the files. I have the names of the 100 .txt files which are also found in the 300 .txt files. How can I extract only the 100 .txt files from the 300 ,txt files? e.g given d1.txt, ds.txt, dx.txt, df.txt...d300.txt, how

Re: [R] Select fixed number of elements

2013-10-30 Thread Alaios
Thumbs up! It worked! On Wednesday, October 30, 2013 9:41 AM, Gerrit Eichner wrote: Hello, Alaois, if x is your vector maybe n <- length( x) positions <- trunc( quantile( seq( n), prob = 0:5/5)) x[ positions] comes close to what you want.   Hth  --  Gerrit > Hi all, I have in my code

Re: [R] Select fixed number of elements

2013-10-30 Thread Ken Knoblauch
Alaios yahoo.com> writes: > I have in my code some vectors that are not of equal size. I would like to be able for each of these vectors > select 6 elements that are (almost) equally spaced. So the first one would be at (or close) to the beginning > the last one at (or close) to the end and the

Re: [R] Select fixed number of elements

2013-10-30 Thread Gerrit Eichner
Hello, Alaois, if x is your vector maybe n <- length( x) positions <- trunc( quantile( seq( n), prob = 0:5/5)) x[ positions] comes close to what you want. Hth -- Gerrit Hi all, I have in my code some vectors that are not of equal size. I would like to be able for each of these vectors sel

[R] Select fixed number of elements

2013-10-30 Thread Alaios
Hi all, I have in my code some vectors that are not of equal size. I would like to be able for each of these vectors select 6 elements that are (almost) equally spaced. So the first one would be at (or close) to the beginning the last one at (or close) to the end and the other 4 equally spaced b

Re: [R] select unique by multiple values

2013-10-09 Thread Bert Gunter
On Wed, Oct 9, 2013 at 11:49 AM, Berend Hasselman wrote: > > On 09-10-2013, at 13:50, Ronald Peterson wrote: > >> Hi, >> >> New to R here. Lots of fun. Still rather green though. >> >> I'd like to select unique items from a list that looks like this (for >> example): >> >>> xyz >> $x >> [1] 8 6

Re: [R] select unique by multiple values

2013-10-09 Thread Ronald Peterson
Very cool! Thanks Berend and arun. R. On Wed, Oct 9, 2013 at 2:49 PM, Berend Hasselman wrote: > > On 09-10-2013, at 13:50, Ronald Peterson wrote: > > > Hi, > > > > New to R here. Lots of fun. Still rather green though. > > > > I'd like to select unique items from a list that looks like thi

Re: [R] select unique by multiple values

2013-10-09 Thread Ronald Peterson
Thanks. That's not quite what I'm looking for, but it's good see different ways to slice and dice data. In my example, the one duplicated x,y pair would 9,9, so I would want to reduce the original list to > xyz $x [1] 8 6 9 0 0 3 9 7 1 $y [1] 1 2 9 5 1 2 0 9 2 $z [1] 5 6 9 0 5 1 1 7 3 and if

Re: [R] select unique by multiple values

2013-10-09 Thread Berend Hasselman
On 09-10-2013, at 13:50, Ronald Peterson wrote: > Hi, > > New to R here. Lots of fun. Still rather green though. > > I'd like to select unique items from a list that looks like this (for > example): > >> xyz > $x > [1] 8 6 9 0 0 3 9 7 1 9 > $y > [1] 1 2 9 5 1 2 0 9 2 9 > $z > [1] 5 6 9 0 5

Re: [R] select unique by multiple values

2013-10-09 Thread arun
[1] 4 A.K. From: Ronald Peterson To: arun Cc: R help Sent: Wednesday, October 9, 2013 1:52 PM Subject: Re: [R] select unique by multiple values Thanks.  That's not quite what I'm looking for, but it's good see different ways to slice and dice

Re: [R] select unique by multiple values

2013-10-09 Thread arun
Hi, Not sure about your expected output. xyz<- list(x=c(8,6,9,0,0,3,9,7,1,9),y=c(1,2,9,5,1,2,0,9,2,9),z=c(5,6,9,0,5,1,1,7,3,4)) indx<-sort(unique(unlist(lapply(xyz[1:2],function(u) which(!duplicated(u))),use.names=FALSE)))  xyz[1:2]<-lapply(xyz[1:2],function(u) u[!duplicated(u)])  xyz[3]$z<-

[R] select unique by multiple values

2013-10-09 Thread Ronald Peterson
Hi, New to R here. Lots of fun. Still rather green though. I'd like to select unique items from a list that looks like this (for example): > xyz $x [1] 8 6 9 0 0 3 9 7 1 9 $y [1] 1 2 9 5 1 2 0 9 2 9 $z [1] 5 6 9 0 5 1 1 7 3 4 I'd like to select unique (x,y), while preserving association wi

Re: [R] Select only rows that don't contain one number

2013-07-30 Thread José María Mateos
2013/7/30 Dimitri Liakhovitski : > How can I grab only those rows that don't contain any -1s (no matter in > what columns? Without writing a loop. > In other words, I want my output to contain only rows 3 and 5 of x. index <- apply(x, 1, function (x) { !(c(-1) %in% x)}) x[index, ] a b c d e 3 2

Re: [R] Select only rows that don't contain one number

2013-07-30 Thread Farhan Ahmed
x[!apply(x, 1, function (y) any(y==-1)),] -- Original Message -- From: "Dimitri Liakhovitski" To: "r-help" Sent: 7/30/2013 10:06:02 AM Subject: [R] Select only rows that don't contain one number Hello! I have a data frame: x<-data.frame(a=c(-1,1,2,3,4),b

Re: [R] Select only rows that don't contain one number

2013-07-30 Thread Bert Gunter
Sums(!x==-1)==ncol(x),] > # a b c d e > #3 2 3 3 4 3 > #5 4 5 5 6 4 > > > A.K. > > > > > - Original Message - > From: Dimitri Liakhovitski > To: r-help > Cc: > Sent: Tuesday, July 30, 2013 10:06 AM > Subject: [R] Select only rows that do

Re: [R] Select only rows that don't contain one number

2013-07-30 Thread arun
)+4*(V2!=-1)+8*(V3!=-1)+16*(V4!=-1)+32*(V5!=-1))) res3<-x1[indx==max(indx),] }) #  user  system elapsed #  0.268   0.008   0.274  identical(res1,res3) #[1] TRUE A.K. - Original Message - From: arun To: Dimitri Liakhovitski Cc: R help Sent: Tuesday, July 30, 2013 10:30 AM Subject

Re: [R] Select only rows that don't contain one number

2013-07-30 Thread arun
x[rowSums(!x<0)==ncol(x),] #if you don't want x<0 #  a b c d e #3 2 3 3 4 3 #5 4 5 5 6 4 #or  x[rowSums(!x==-1)==ncol(x),] #  a b c d e #3 2 3 3 4 3 #5 4 5 5 6 4 A.K. - Original Message - From: Dimitri Liakhovitski To: r-help Cc: Sent: Tuesday, July 30, 2013 10:06 AM

Re: [R] Select only rows that don't contain one number

2013-07-30 Thread Dimitri Liakhovitski
Thanks a a lot, Jose! On Tue, Jul 30, 2013 at 10:19 AM, José María Mateos wrote: > 2013/7/30 Dimitri Liakhovitski : > > How can I grab only those rows that don't contain any -1s (no matter in > > what columns? Without writing a loop. > > In other words, I want my output to contain only rows 3 an

[R] Select only rows that don't contain one number

2013-07-30 Thread Dimitri Liakhovitski
Hello! I have a data frame: x<-data.frame(a=c(-1,1,2,3,4),b=c(1,-1,3,4,5),c=1:5,d=2:6,e=c(1,2,3,-1,4)) x How can I grab only those rows that don't contain any -1s (no matter in what columns? Without writing a loop. In other words, I want my output to contain only rows 3 and 5 of x. Thank you ve

Re: [R] Select csv files by choosing datetime

2013-07-23 Thread Akkara, Antony (GE Power & Water, Non-GE)
th, pattern = "*.csv", all.files = FALSE, : could not find function "file.info<-"] But how can I get filenames along with path which is created between(modified date) two date/time. Thanks Antony. -Original Message- From: Akkara, Antony (GE Energy, Non-GE) Sent

  1   2   3   4   5   >