Re: [R] find and

2017-03-20 Thread Bert Gunter
Here is a version similar to Rui's, but using ave() and logical indexing to simplify a bit: > DF4[with(DF4, ave(as.numeric(var), city, FUN = function(x)length(unique(x))) > ==1), ] city wk var 4 city2 1 x 5 city2 2 x 6 city2 3 x 7 city2 4 x 8 city3 1 x 9 city3 2 x 10

Re: [R] find and

2017-03-18 Thread Ashta
Thank you Rudi and Ulrik. Rudi, your option worked for the small data set but when I applied to the big data set it taking long and never finished and have to kill it. I dont know why. Ulrik's option worked fine for the big data set (> 1.5M records) and took less than 2 minutes. These two ar

Re: [R] find and

2017-03-18 Thread Ulrik Stervbo
Using dplyr: library(dplyr) # Counting unique DF4 %>% group_by(city) %>% filter(length(unique(var)) == 1) # Counting not duplicated DF4 %>% group_by(city) %>% filter(sum(!duplicated(var)) == 1) HTH Ulrik On Sat, 18 Mar 2017 at 15:17 Rui Barradas wrote: > Hello, > > I believe this do

Re: [R] find and

2017-03-18 Thread Rui Barradas
Hello, I believe this does it. sp <- split(DF4, DF4$city) want <- do.call(rbind, lapply(sp, function(x) if(length(unique(x$var)) == 1) x else NULL)) rownames(want) <- NULL want Hope this helps, Rui Barradas Em 18-03-2017 13:51, Ashta escreveu: Hi all, I am trying to find a

[R] find and

2017-03-18 Thread Ashta
Hi all, I am trying to find a city that do not have the same "var" value. Within city the var should be the same otherwise exclude the city from the final data set. Here is my sample data and my attempt. City1 and city4 should be excluded. DF4 <- read.table(header=TRUE, text=' city wk var city1

Re: [R] Find and replace backslashes XXXX

2015-05-27 Thread Duncan Murdoch
On 27/05/2015 8:55 AM, Dan Abner wrote: > Hi Ista, > > Is there no way to not escape the backslash in the pathway? You don't need to escape it if you read it from a file, get it from list.files(), etc. You only need to escape it if you are writing a literal string in R code. Duncan Murdoch Th

Re: [R] Find and replace backslashes XXXX

2015-05-27 Thread Dan Abner
Hi Ista, Is there no way to not escape the backslash in the pathway? The pathway is going to change and will become very long and I need to do this programmatically. Beside, escaping the backslash defeats the purpose of using gsub. If I could do this manually each and every time, I would change si

Re: [R] Find and replace backslashes XXXX

2015-05-27 Thread Thierry Onkelinx
Since the character looks like a Windows file path, you could use normalizePath() instead of gsub(). normalizePath("X:\\Classes\\TT\\Automation", winslash = "/", mustWork = FALSE) ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie

Re: [R] Find and replace backslashes XXXX

2015-05-27 Thread Duncan Murdoch
On 26/05/2015 9:56 PM, Ista Zahn wrote: > Escape the backslash with another backslash, i.e., > > gsub("\\","/","X:\\Classes\\TT\\Automation", fixed = TRUE) ... and note that if you want to use a regular expression (i.e. fixed = FALSE), you would need another level of escaping, i.e. gsub("","

Re: [R] Find and replace backslashes XXXX

2015-05-26 Thread Ista Zahn
Escape the backslash with another backslash, i.e., gsub("\\","/","X:\\Classes\\TT\\Automation", fixed = TRUE) best, Ista On Tue, May 26, 2015 at 9:30 PM, Dan Abner wrote: > Hi all, > > I realize that the backslash is an escape character in R, therefore, I > am trying to replace it with a forwar

[R] Find and replace backslashes XXXX

2015-05-26 Thread Dan Abner
Hi all, I realize that the backslash is an escape character in R, therefore, I am trying to replace it with a forward slash. Can someone please suggest how to get this code to work? > lib<-gsub("\","/","X:\Classes\TT\Automation") Error: unexpected symbol in "lib<-gsub("\","/","X" Thanks, Dan

Re: [R] find and remove outlier

2015-01-05 Thread John Fox
Dear Pushpa Methekar, You can use which.max(), as in > library(car) > mod <- lm(prestige~ income + education, data=Duncan) > which.max(abs(rstudent(mod))) minister 6 In fact, this is exactly what outlierTest() does, as you can see by looking at car:::outlierTest.lm Beyond that, I'd en

[R] find and remove outlier

2015-01-05 Thread Methekar, Pushpa (GE Transportation, Non-GE)
Hi, this is my function to find rstudent of model which will give me outlier But I wonder if I could find out the exact no. of outlier in data set. Like outlierTest() does from car package . rm.outliers = function(dataset,model){ dataset$rstudent = rstudent(model) for(i in 1:length(dataset$rstu

Re: [R] find and add text

2013-10-26 Thread arun
Hi, No problem. Try: data.frame(col1=data,col2=as.character(factor(gsub("\\d+","",data),labels=c("positive","negative"))),stringsAsFactors=FALSE) A.K. Hello Arun, Thank you so much,  it works great. But I some sets, the data contains some additional characters also, like a1, a2, a3..

Re: [R] find and add text

2013-10-26 Thread arun
Hi, You may try: dat2 <- data.frame(col1=data,col2=as.character(factor(data,labels=c("positive","negative"))),stringsAsFactors=FALSE) A.K. Hello all, I have a data something like this; data<- c("a", "b","b","b","a","a","b","a","b") and I need to represent all "a"'s as "positive"  and "b"

Re: [R] find and replace missing data in several different files

2013-04-27 Thread Zilefac Elvis
Hello, I have a question and need your help urgently. I am new to R but want to learn it. I have several files in a folder which I have imported to R using : temp = list.files(pattern="*.txt") >myfiles = lapply(temp, read.delim) The resulting files are on the workspace stored as List[110]. So

Re: [R] find and replace characters in a string

2013-03-27 Thread PIKAL Petr
Wednesday, March 27, 2013 5:17 PM > To: Shane Carey > Cc: r-help@r-project.org > Subject: Re: [R] find and replace characters in a string > > Hello, > > The period is a metacharacter so you have to escape it. > The period is escaped with a '\'. In it's turn, 

Re: [R] find and replace characters in a string

2013-03-27 Thread Rui Barradas
Hello, The period is a metacharacter so you have to escape it. The period is escaped with a '\'. In it's turn, '\' is a metacharacter so it needs to be escaped. Hence the double'\\'. x <- "LOI ." gsub("\\.", "(%)", x) Hope this helps, Rui Barradas Em 27-03-2013 16:09, Shane Carey escreveu:

Re: [R] find and replace characters in a string

2013-03-27 Thread arun
txt<-  "LOI ." gsub("[.]","%",txt) #[1] "LOI %" A.K. From: Shane Carey To: r-help@r-project.org Sent: Wednesday, March 27, 2013 12:09 PM Subject: [R] find and replace characters in a string Hi, I have a string o

[R] find and replace characters in a string

2013-03-27 Thread Shane Carey
Hi, I have a string of text as follows "LOI ." How do I replace the dot with "(%)" gsub(".","(%)",LOI .) gives "(%)(%)(%)(%)(%)" Thanks -- Shane [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.c

Re: [R] find and replace

2012-08-28 Thread arun
v_Place) Students1 #   ID   Name    Fav_Place #1 101 Andrew    Tucson AZ #2 201   John    San Francisco #3 303  Julie California/New York City #4 304 Monica    New York City A.K. - Original Message - From: Sapana Lohani To: R help Cc: Sent: Mond

Re: [R] find and replace

2012-08-28 Thread arun
ot;ID Name Fav_Place"  "101 Andrew  Tucson,AZ" #[3] "201 John SanFrancisco"  "303 Julie California/New York City" #[5] "304 Monica  New York City" A.K. - Original Message - From: Sapana Lohani To: R help

Re: [R] find and replace

2012-08-28 Thread arun
essage - From: Sapana Lohani To: R help Cc: Sent: Monday, August 27, 2012 4:19 PM Subject: [R] find and replace I have 5 (A,B,C,D,E) columns in my dataframe. I want to replace all "x" with "y" and all "a" with "b"

Re: [R] find and replace

2012-08-27 Thread R. Michael Weylandt
Take a look at gsub() Michael On Aug 27, 2012, at 6:47 PM, Sapana Lohani wrote: > Hi, > > My data frame (Students) is > > ID Name Fav_Place > 101 Andrew� Phoenix AZ > 201 John San Francisco > 303 JulieCalifornia / New York > 304 Monica� New York > > How can I replace Phoenix with Tucson & N

[R] find and replace

2012-08-27 Thread Sapana Lohani
Hi, My data frame (Students) is ID Name Fav_Place 101 Andrew  Phoenix AZ 201 John San Francisco 303 JulieCalifornia / New York 304 Monica  New York How can I replace Phoenix with Tucson & New York with New York City in the df? Thanks [[alternative HTML version deleted]] __

Re: [R] find and replace

2012-08-27 Thread jim holtman
I am making the assumption that all the columns are character and not factors: for (i in c("A", "B", "C", "D", "E")){ yourdf[[i]] <- ifelse(yourdf[[i]] == 'x' , 'y' , ifelse(yourdf[[i]] == 'a' , 'b' , yourd

[R] find and replace

2012-08-27 Thread Sapana Lohani
I have 5 (A,B,C,D,E) columns in my dataframe. I want to replace all "x" with "y" and all "a" with "b" within these 5 columns. Can I do it in one step? Thanks [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat

Re: [R] Find and install old package to R 2.11 in UNIX

2012-08-17 Thread Uwe Ligges
On 17.08.2012 02:42, David Winsemius wrote: On Aug 16, 2012, at 4:33 PM, Kevin Goulding wrote: Hi, I'm having trouble installing and using the 'foreign' package in R on a UNIX machine. sessionInfo() R version 2.11.1 (2010-05-31) sparc-sun-solaris2.10 locale: [1] C at

Re: [R] Find and install old package to R 2.11 in UNIX

2012-08-16 Thread David Winsemius
On Aug 16, 2012, at 4:33 PM, Kevin Goulding wrote: Hi, I'm having trouble installing and using the 'foreign' package in R on a UNIX machine. sessionInfo() R version 2.11.1 (2010-05-31) sparc-sun-solaris2.10 locale: [1] C attached base packages: [1] stats graph

[R] Find and install old package to R 2.11 in UNIX

2012-08-16 Thread Kevin Goulding
Hi, I'm having trouble installing and using the 'foreign' package in R on a UNIX machine. > sessionInfo() R version 2.11.1 (2010-05-31) sparc-sun-solaris2.10 locale: [1] C attached base packages: [1] stats graphics grDevices utils datasets methods base

Re: [R] find and replace string

2011-12-02 Thread Sarah Goslee
You've been given a workable solution already, but here's a one-liner: > x <- c('sta_+1+0_field2ndtry_$01.cfg' , > 'sta_+B+0_field2ndtry_$01.cfg' , 'sta_+1+0_field2ndtry_$01.cfg' , > 'sta_+9+0_field2ndtry_$01.cfg') > sapply(1:length(x), function(i)gsub("\\+(.*)\\+.", paste("\\+\\

Re: [R] find and replace string

2011-12-02 Thread Alaios
You are too good :) Thanks a lot have a nice weekend B.R Alex From: jim holtman Cc: "R-help@r-project.org" Sent: Friday, December 2, 2011 1:51 PM Subject: Re: [R] find and replace string try this: > x <- c('sta_+1+0_fi

Re: [R] find and replace string

2011-12-02 Thread christiaan pauw
If the length of the fists part is constant (the "sta_+1+" part) the you can use substr() On 2 December 2011 13:30, Alaios wrote: > Dear all, > I would like to search in a string for the second occurrence of a symbol and > replace the symbol after it > > For example my strings look like > >

Re: [R] find and replace string

2011-12-02 Thread jim holtman
try this: > x <- c('sta_+1+0_field2ndtry_$01.cfg' + , 'sta_+1+0_field2ndtry_$01.cfg' + , 'sta_+1-0_field2ndtry_$01.cfg' + , 'sta_+1+0_field2ndtry_$01.cfg' + ) > # find matching fields > values <- grep("[^+]*\\+[^+]*\\+0", x, value = TRUE) > # split into two piec

[R] find and replace string

2011-12-02 Thread Alaios
Dear all, I would like to search in a string for the second occurrence of a symbol and replace the symbol after it For example my strings look like sta_+1+0_field2ndtry_$01.cfg I want to find the digit that comes after the second +, in that case is zero and then over a loop create the strin

Re: [R] Find and replace all the elements in a data frame

2011-02-17 Thread Gong-Yi Liao
You may write as this: for (i in 1:nrow(x)){ for (j in 1:ncol(x)){ if (!is.na(x[i, j])) { if(x[i, j] == 'A') {x2[i, j] <- 'A/A'} else{ if(x[i, j] == 'T') {x2[i, j] <- 'T/T'} else{ if(x[i, j] == 'G') {x2[i, j] <- 'G/G'} else{

Re: [R] Find and replace all the elements in a data frame

2011-02-17 Thread baptiste auguie
Hi, You could use car::recode to change the levels of the factors, library(car) transform(x, locus1 = recode(locus1, "'A' = 'A/A' ; else = 'T/T'"), locus2 = recode(locus2, "'T'='T/T' ; 'C' = 'C/C'"), locus3 = recode(locus3, "'C'='C/C' ; 'G' = 'G/G'")) HTH

Re: [R] Find and replace all the elements in a data frame

2011-02-17 Thread Henrique Dallazuanna
Try this: xNew <- as.data.frame(mapply(paste, x, x, sep = "/")) xNew[is.na(x)] <- NA xNew On Thu, Feb 17, 2011 at 2:54 PM, Josh B wrote: > Hi all, > > I'm having a problem once again, trying to do something very simple. > Consider > the following data frame: > > x <- read.table(textConnection("

Re: [R] Find and replace all the elements in a data frame

2011-02-17 Thread Sarah Goslee
Josh, you've made it far too complicated. Here's one simpler way (note that I changed your read.table statement to make the values NOT factors, since I wouldn't think you want that). > x <- read.table(textConnection("locus1 locus2 locus3 + A T C + A T NA + T C C + A T G"), header = TRUE, as.is=TRU

[R] Find and replace all the elements in a data frame

2011-02-17 Thread Josh B
Hi all, I'm having a problem once again, trying to do something very simple. Consider the following data frame: x <- read.table(textConnection("locus1 locus2 locus3 A T C A T NA T C C A T G"), header = TRUE) closeAllConnections() I am trying to make a new data frame, replacing "A" with "A/A", "

Re: [R] Find and remove elemnts of a data frame

2011-01-06 Thread Alaios
Thanks a lot worked fine Regards --- On Thu, 1/6/11, John Kane wrote: From: John Kane Subject: Re: [R] Find and remove elemnts of a data frame To: r-help@r-project.org, "Alaios" Date: Thursday, January 6, 2011, 3:27 PM With dataframe xx (naming a data.frame as data.frame is a

Re: [R] Find and remove elemnts of a data frame

2011-01-06 Thread John Kane
With dataframe xx (naming a data.frame as data.frame is a bit dicey subset(xx, xx[,4]> -45) --- On Thu, 1/6/11, Alaios wrote: > From: Alaios > Subject: [R] Find and remove elemnts of a data frame > To: r-help@r-project.org > Received: Thursday, January 6, 2011, 10:07 AM > De

[R] Find and remove elemnts of a data frame

2011-01-06 Thread Alaios
Dear all, I have a data frame that is created like that data.frame(x=CRX[-1],y=CRY[-1],z=CRagent[[1]]$sr) the output looks like 45 116 162 -30.89105988567164 46 128  79 -42.66296679571184 47 180 195 -30.45626175641315 48 114  83 -45.26843476475688 49 118  73 -46.85389245327003 How can I select