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
À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
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", ][
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
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",
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
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
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"
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
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
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,
Yes, should be 6 0.2. The code worked. Thank you!
>>> William Dunlap 12/03/09 12:07 PM >>>
> -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.
> -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,
>
> I have a vector like this:
>
>
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
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
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
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
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
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
> 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
>
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:
> 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
___
> 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
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
> 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
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
> 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
> -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 might be a hundred times
> answere
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
29 matches
Mail list logo