Re: [R] Replace values based on neither condition

2022-10-28 Thread Luigi Marongiu
Perfect, thank you! On Fri, Oct 28, 2022 at 11:53 AM Rui Barradas wrote: > > Às 10:43 de 28/10/2022, Luigi Marongiu escreveu: > > Hello, > > I have a data frame with a string column. All data that are neither > > "POS" nor "NEG" should've replaced by an NA. How can I implement that > > (even with

Re: [R] Replace values based on neither condition

2022-10-28 Thread Rui Barradas
Às 10:43 de 28/10/2022, Luigi Marongiu escreveu: Hello, I have a data frame with a string column. All data that are neither "POS" nor "NEG" should've replaced by an NA. How can I implement that (even with extra libraries)? My attempts actually wipe out POS and NEG... Thank you ``` df = data.fram

[R] Replace values based on neither condition

2022-10-28 Thread Luigi Marongiu
Hello, I have a data frame with a string column. All data that are neither "POS" nor "NEG" should've replaced by an NA. How can I implement that (even with extra libraries)? My attempts actually wipe out POS and NEG... Thank you ``` df = data.frame(a = 1:5, b = c("", "31.35", "POS", "20.61"

Re: [R] Replace values in a dataframe

2015-06-17 Thread Grams Robins via R-help
Try this:  dat=structure(list(Color = c("5", "<4","5", "<5", "5"), Unit = c("Hazen","Hazen","Hazen", "Hazen", "Hazen")), .Names = c("Color", "Unit"), row.names =c("1:2","1:3", "1:4", "1:5","1:6"), class = "data.frame") dat=as.data.frame(dat)dat$col2 <- rep(" ", nrow(dat))dat[dat$Color == "<4", ][

Re: [R] Replace values in a dataframe

2015-06-17 Thread Bert Gunter
Is the following what you want: (z is your data frame) > change <-c("2","2.5") > names(change) <- c("<4","<5") (note: this can be automated using regular expressions and will work for lots more values to change. Sarah's ifelse() solution is fine for the example, but becomes too cumbersome (as sh

Re: [R] Replace values in a dataframe

2015-06-17 Thread Sarah Goslee
Hi Shane, On Wed, Jun 17, 2015 at 1:31 PM, Shane Carey wrote: > Hey all, > > I have a dataframe that consists of: > > structure(list(Color = c("5", "<4","5", "<5", "5"), Unit = c("Hazen", > "Hazen", > "Hazen", "Hazen", "Hazen")), .Names = c("Color", "Unit"), row.names = > c("1:2", > "1:3", "1:4",

[R] Replace values in a dataframe

2015-06-17 Thread Shane Carey
Hey all, I have a dataframe that consists of: structure(list(Color = c("5", "<4","5", "<5", "5"), Unit = c("Hazen", "Hazen", "Hazen", "Hazen", "Hazen")), .Names = c("Color", "Unit"), row.names = c("1:2", "1:3", "1:4", "1:5","1:6"), class = "data.frame") I need to find the <4 and have a new colum

Re: [R] replace values in one df by values from key pairs in another df

2015-02-13 Thread arnaud gaboury
This is the wrong part of my code. > >> idName=users[users$id %in% ext] > idname > 1: U03AEKWTL agreenmamba > 2: U032FHV3S poisonivy > 3: U03AEKYL4 vairis > Best is to use: idNames <- users[pmatch(ext, users$id, duplicates.ok = T)]. This leave me with an ordered and dupl

[R] replace values in one df by values from key pairs in another df

2015-02-13 Thread arnaud gaboury
I have been searching for a while now, but can't put all pieces of the puzzle together. Goal : I want to replace all these kinds of patterns <@U032FHV3S> by this <@agreenmamba>. In a more generic way, it is replacing 'id' by user 'name'. I have two df: The first, 'history', is some message histor

Re: [R] replace values in vector from a replacement table

2012-07-31 Thread Liviu Andronic
On Mon, Jul 30, 2012 at 6:00 PM, jim holtman wrote: > try this: > >> (x <- rep(letters,2)) > [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" > "q" "r" "s" "t" "u" "v" "w" > [24] "x" "y" "z" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" > "n" "o" "p" "q" "r" "s" "t" > [47

Re: [R] replace values in vector from a replacement table

2012-07-30 Thread Liviu Andronic
On Mon, Jul 30, 2012 at 6:00 PM, jim holtman wrote: > try this: >> indx <- match(x, repl.tab[, 1], nomatch = 0) >> x[indx != 0] <- repl.tab[indx, 2] >> x > [1] "A" "B" "c" "D" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" > "q" "r" "s" "t" "u" "v" "w" > [24] "x" "y" "z" "A" "B" "c" "D" "e" "f"

Re: [R] replace values in vector from a replacement table

2012-07-30 Thread jim holtman
try this: > (x <- rep(letters,2)) [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" [24] "x" "y" "z" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" [47] "u" "v" "w" "x" "y" "z" > values <- c("aa", "a", "b", NA, "d", "z

[R] replace values in vector from a replacement table

2012-07-30 Thread Liviu Andronic
Dear all I've got stuck when trying to replace values in a vector by selecting replacements from a replacement table. I'm trying to use only base functions. Here's a dummy example: > (x <- rep(letters,2)) [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" [

Re: [R] replace values

2011-12-03 Thread David Winsemius
On Dec 3, 2011, at 8:41 AM, syrvn wrote: Hello, imagine the following data.frame: ID name 1 *_A 2 *_A 3 *_B 4 *_B * = can be any pattern I want to replace every row which ends with _A by 1 and every row which ends by _B with a 0 You can use grep(patt, x, value=TRUE) to return vlaues t

[R] replace values

2011-12-03 Thread syrvn
Hello, imagine the following data.frame: ID name 1 *_A 2 *_A 3 *_B 4 *_B * = can be any pattern I want to replace every row which ends with _A by 1 and every row which ends by _B with a 0 so that the data.frame looks like the following: ID name 1 1 2 1 3 0 4 0 Which function do I use best

Re: [R] replace values in array with means of certain values in array

2011-01-10 Thread Petr Savicky
On Mon, Jan 10, 2011 at 03:21:18PM +0100, joke R wrote: > Dear all, > > I have a problem with arrays. > Simplified, I have two arrays: > > A = > [,,1] > 1 2 3 > 4 5 6 > 7 8 9 > > [,,2] > 10 11 12 > 13 14 15 > 16 17 18 > > B= > 1 1 2 > 1 1 2 > 3 3 2 > > Basically,

[R] replace values in array with means of certain values in array

2011-01-10 Thread joke R
Dear all, I have a problem with arrays. Simplified, I have two arrays: A = [,,1] 1 2 3 4 5 6 7 8 9 [,,2] 10 11 12 13 14 15 16 17 18 B= 1 1 2 1 1 2 3 3 2 Basically, B declares to which cluster the values of A belong to. Now I want an array C where for each cluster

[R] replace values of a table !!!

2010-12-21 Thread Taiseer Aljazzar
Dear all, Dear all, I am a relatively new user. I have an ascii file with 550 rows and 400 columns. The file contain values ranging from 1 to 2000 and some values with -. I want to generate a new file where the - values are replaced with 0 values, the other values with the 1.0 value.

Re: [R] Replace values in a vector

2009-12-03 Thread Farida Mostajabi
3, 2009 8:41 AM > To: r-help@r-project.org > Subject: [R] Replace values in a vector > > Hi all, > > I have a vector like this: > > x<- c(0.7, 0.1, 0, 0.2, 0.2, 0, 0, 0 , 0, 0.4, 0, 0.8, 1.8) > > I would like to replace the zero values with the first > previous non

Re: [R] Replace values in a vector

2009-12-03 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Farida Mostajabi > Sent: Thursday, December 03, 2009 8:41 AM > To: r-help@r-project.org > Subject: [R] Replace values in a vector > > Hi all, >

Re: [R] Replace values in a vector

2009-12-03 Thread Farida Mostajabi
WOW! It worked. Thank you! >>> Gabor Grothendieck 12/03/09 11:46 AM >>> na.locf in the zoo package takes the last occurrence and carries it forward into NAs so replace your zeros with NAs and then apply na.locf like this: library(zoo) na.locf(replace(x, x==0, NA)) On Thu, Dec 3, 2009 at

Re: [R] Replace values in a vector

2009-12-03 Thread Gabor Grothendieck
na.locf in the zoo package takes the last occurrence and carries it forward into NAs so replace your zeros with NAs and then apply na.locf like this: library(zoo) na.locf(replace(x, x==0, NA)) On Thu, Dec 3, 2009 at 11:41 AM, Farida Mostajabi wrote: > Hi all, > > I have a vector like this

[R] Replace values in a vector

2009-12-03 Thread Farida Mostajabi
Hi all, I have a vector like this: x<- c(0.7, 0.1, 0, 0.2, 0.2, 0, 0, 0 , 0, 0.4, 0, 0.8, 1.8) I would like to replace the zero values with the first previous non zero value. my returning vector should look like this: y<-c( 0.7, 0.1, 0.1,0.2,0.2,0.2,0.2,0.2, 0.4, 0.4, 0.8, 1.8) How can I do

Re: [R] Replace Values in Matrix

2009-11-27 Thread smu
matritz[is.na(matritz)] <- 0 On Fri, Nov 27, 2009 at 04:15:45PM -0200, Romildo Martins wrote: > Hello, > > how to replace the "NA" by number zero? > > > matrizt > [,1] [,2] [,3][,4] > [1,] 1.000NA NA NA > [2,] 0

Re: [R] Replace Values in Matrix

2009-11-27 Thread baptiste auguie
Hi, Try this, matrizt[is.na(matrizt)] <- 0 HTH, baptiste 2009/11/27 Romildo Martins : > Hello, > > how to replace the "NA" by number zero? > >> matrizt >                 [,1]           [,2]             [,3]        [,4] > [1,] 1.000            NA             NA         NA > [2,] 0.6717685 0

[R] Replace Values in Matrix

2009-11-27 Thread Romildo Martins
Hello, how to replace the "NA" by number zero? > matrizt [,1] [,2] [,3][,4] [1,] 1.000NA NA NA [2,] 0.6717685 0.1453253 NA NA [3,] 0.3971276 0.1493241 0.14532526 NA [4,] 0.1493241 0.1453

Re: [R] Replace values according to conditions

2008-04-09 Thread Suhaila Zainudin
Thanks for all the reply. I solved the task using apply(as suggested by Hans). The tips on S-Poetry and ?Logic are very handy as well. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinf

[R] R: Replace values according to conditions

2008-04-09 Thread Guazzetti Stefano
ano -Messaggio originale- Da: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] conto di Suhaila Zainudin Inviato: mercoledì 9 aprile 2008 9.32 A: r-help@r-project.org Oggetto: [R] Replace values according to conditions Greetings R-users, I have the following data called mydata in a data.frame Col1

Re: [R] Replace values according to conditions

2008-04-09 Thread Hans-Joerg Bibiko
On 9 Apr 2008, at 09:51, [EMAIL PROTECTED] wrote: >> I have the following data called mydata in a data.frame >> >> Col1 Col2 Col3 Col4 Col5 >> 1 2 46 7 >> 8 8 73 5 >> 4 4 56 7 >> >> I want to replace the data according to the following condit

Re: [R] Replace values according to conditions

2008-04-09 Thread Richard . Cotton
> I have the following data called mydata in a data.frame > > Col1 Col2 Col3 Col4 Col5 > 1 2 46 7 > 8 8 73 5 > 4 4 56 7 > > I want to replace the data according to the following conditions > > Condition 1 if data <= 3, replace with -1 >

[R] Replace values according to conditions

2008-04-09 Thread Suhaila Zainudin
Greetings R-users, I have the following data called mydata in a data.frame Col1 Col2 Col3 Col4 Col5 1 2 46 7 8 8 73 5 4 4 56 7 I want to replace the data according to the following conditions Condition 1 if data <= 3, replace with -1 Co

Re: [R] Replace values in data.frame conditional on another data.frame

2008-03-05 Thread John Kane
Try bb[is.na(aa)] <- NA It may be simple but it is not necessarily obvious :) --- Carson Farmer <[EMAIL PROTECTED]> wrote: > Dear List, > > I am looking for an efficient method for replacing > values in a > data.frame conditional on the values of a separate > data.frame. Here is > my scenario:

[R] Replace values in data.frame conditional on another data.frame

2008-03-05 Thread Carson Farmer
Dear List, I am looking for an efficient method for replacing values in a data.frame conditional on the values of a separate data.frame. Here is my scenario: I have a data.frame (A) with say 1000 columns, and 365 rows. Each cell in the data.frame has either valid value, or NA. I have an additional

Re: [R] Replace values on seq

2007-10-23 Thread Walter Alini
> I will report results then, OK, its better this way, but no so much. Before: 99.79 (a) vs 0.21 (b) Now: 99.77 (a) vs 0.23 (b) But these results continue to be surprising for me. Ok. Thanks you guys again, I will continue bothering you sometime. Walter ___

Re: [R] Replace values on seq

2007-10-23 Thread Walter Alini
> Does this help clarify the differences? For sure! Thanks Jim. I will test with the solutions you gave me, maybe the differences are not so big, I was just surprised about that. I will report results then, Thanks! Walter __ R-help@r-project.org mail

Re: [R] Replace values on seq

2007-10-23 Thread jim holtman
Well you do know that R is 'interpreted' and that C is 'compiled'. In R you are calling functions to perform the operations. There is a function for indexing ('['): > get ("[") .Primitive("[") So your 'for' statement in R is interpreting the R code and calling some functions to perform the oper

Re: [R] Replace values on seq

2007-10-23 Thread Walter Alini
> code (C in this case). What exactly are you asking? You can alway > 'time' (sys.time) a set of statements to see which is better (just > make sure you execute them enough times to get reasonable readings -- > several seconds) I was wondering where to seach for the code of these different optio

Re: [R] Replace values on seq

2007-10-23 Thread jim holtman
Guilty of what? What are you trying to compare? Now all the approaches do get down to 'loops' being performed in the base level code (C in this case). What exactly are you asking? You can alway 'time' (sys.time) a set of statements to see which is better (just make sure you execute them enough

Re: [R] Replace values on seq

2007-10-23 Thread Walter Alini
> Hope this is helpful, Certainly! Thanks Dan and Jim! Now, I wonder where I can dig in to realize why this is better. Is C code for this function better than others? Is C guilty on this? Maybe I am too newbie. Thanks again, guys! Walter __ R-help@r

Re: [R] Replace values on seq

2007-10-23 Thread Nordlund, Dan (DSHS/RDA)
> -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Walter Alini > Sent: Tuesday, October 23, 2007 1:18 PM > To: r-help@r-project.org > Subject: [R] Replace values on seq > > Hey guys, sorry for the inconvenience (this

Re: [R] Replace values on seq

2007-10-23 Thread jim holtman
Is this what you want to do? > table <- seq(255, 0, by=-1) > data <- c(1,8,34,100) > data <- table[data + 1] > data [1] 254 247 221 155 On 10/23/07, Walter Alini <[EMAIL PROTECTED]> wrote: > Hey guys, sorry for the inconvenience (this might be a hundred times > answered question), but I have bee

[R] Replace values on seq

2007-10-23 Thread Walter Alini
Hey guys, sorry for the inconvenience (this might be a hundred times answered question), but I have been searching a while and gave up about the following: I have the following, table and data: table <- seq(255, 0, by=-1) data <- c(1,8,...) <--- doesn't matter what's in here Which would be th