ifelse(side ==
'SELL', -1, NA)))
is an option that would take care of other options.
-Original Message-
From: R-help On Behalf Of Ben Bolker
Sent: Friday, September 29, 2023 10:00 AM
To: r-help@r-project.org
Subject: Re: [R] replace character by numeric value
[External Email]
--Original Message-
From: R-help On Behalf Of Enrico Schumann
Sent: Thursday, September 28, 2023 3:13 AM
To: arnaud gaboury
Cc: r-help
Subject: Re: [R] replace character by numeric value
[External Email]
On Wed, 27 Sep 2023, arnaud gaboury writes:
I have two data.frames:
mydf1 <- stru
Does this work?
mynewdf$side <- as.numeric(mynewdf$side)
This code would be the next line after your mutate.
TIm
-Original Message-
From: R-help On Behalf Of Enrico Schumann
Sent: Thursday, September 28, 2023 3:13 AM
To: arnaud gaboury
Cc: r-help
Subject: Re: [R] replace character
On Thu, Sep 28, 2023 at 8:18 AM Ivan Calandra wrote:
>
> Dear Arnaud,
>
> I don't quite unterstand why you have imbricated ifelse() statements. Do
> you have more that BUY (1) and SELL (-1)? If not, why not simply:
> mynewdf2 <- mydf2 |> dplyr::mutate(side = ifelse(side == 'BUY', 1, -1))
Yes it w
On Wed, 27 Sep 2023, arnaud gaboury writes:
> I have two data.frames:
>
> mydf1 <- structure(list(symbol = "ETHUSDT", cummulative_quote_qty =
> 1999.9122, side = "BUY", time = structure(1695656875.805, tzone = "", class
> = c("POSIXct", "POSIXt"))), row.names = c(NA, -1L), class = c("data.table",
Dear Arnaud,
I don't quite unterstand why you have imbricated ifelse() statements. Do
you have more that BUY (1) and SELL (-1)? If not, why not simply:
mynewdf2 <- mydf2 |> dplyr::mutate(side = ifelse(side == 'BUY', 1, -1))
That would solve the problem. I'm not quite sure exactly what happens,
I have two data.frames:
mydf1 <- structure(list(symbol = "ETHUSDT", cummulative_quote_qty =
1999.9122, side = "BUY", time = structure(1695656875.805, tzone = "", class
= c("POSIXct", "POSIXt"))), row.names = c(NA, -1L), class = c("data.table",
"data.frame"))
mydf2 <- structure(list(symbol = c("ET
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
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"
There probably is a package with such a function, but you can do with one
call to sub() if you parenthesize all the subexpressions in the regular
expression and use \\1, etc., in the replacement for those parts you want
to keep. E.g.,
> s <- ""
> want <- ""
> new_regexp <- "(.*<[^>]+ data-pos=\"
An R regular expression pattern can contain parenthesized
subexpressions, and those can be used later in the same pattern, or in
the replacement in sub() and gsub(). What I'd like to do is match
several subexpressions and replace all of them.
For example, I might have a string like
s <-
Hi Kai,
You can also try this:
proband_crc2 %>%
mutate(MMR = replace(MMR, MMR =="NA", "-"))
Thanks,
Kostas
On Wed, Jun 2, 2021 at 11:59 AM Jim Lemon wrote:
> Hi Kai,
> Maybe this will help:
>
> proband_crc2<-data.frame(MMR=rep(c(NA,"+"),3))
> proband_crc2
> proband_crc2$MMR[is.na(proband_cr
Hello Jim,Your example works well.Thank you for your help,Kai
On Tuesday, June 1, 2021, 04:59:09 PM PDT, Kai Yang via R-help
wrote:
Hi List,
I have a column MMR in a data frame proband_crc2. The column contents missing
value and + (means positive).
I need to replace all missing value
Hi Kai,
Maybe this will help:
proband_crc2<-data.frame(MMR=rep(c(NA,"+"),3))
proband_crc2
proband_crc2$MMR[is.na(proband_crc2$MMR)]<-"-"
proband_crc2
Jim
On Wed, Jun 2, 2021 at 9:59 AM Kai Yang via R-help wrote:
>
> Hi List,
> I have a column MMR in a data frame proband_crc2. The column content
A unary negative sign with no number is not a number, so it has to be
character. If you are done with computations you can format your numbers as
character data and set the NA to "-", but such a conversion will prevent you
from performing computations so it is only useful for creating report tab
Hi List,
I have a column MMR in a data frame proband_crc2. The column contents missing
value and + (means positive).
I need to replace all missing value into - (means negative)
I did try with difference ways. Below are my testing, but not any one works.
Can someone help me?
Thanks,
Kai
proband_
-project.org
Subject: Re: [R] replace zero in a matrix using random numbers
?rnorm tells you that n, the first argument, is the number of
observations/random numbers you wish to generate. You asked for 1.
So you need to ask for the number of 0's, something like:
> a <- matrix(rep(0:1,
?rnorm tells you that n, the first argument, is the number of
observations/random numbers you wish to generate. You asked for 1.
So you need to ask for the number of 0's, something like:
> a <- matrix(rep(0:1, 3), nrow =3)
> a
[,1] [,2]
[1,]01
[2,]10
[3,]01
> a[!a] <-
Hello,
Try to get the number of zero values before:
i <- er.miRCounts == 0
n <- sum(i)
er.miRCounts[i] <- rnorm(n,mean=1, sd=0.1)
Also, there is no need for a end-of-instruction ';'.
The semi-colon is the instruction separator, so if you put it at the end
you will be separating the instructio
Hi R users,
I am analyzing miRNA sequence data for a special network analysis, I need to
replace zero values in a matrix as random numbers with mean of 1 and standard
deviation of 0.1.
er.miRCounts[er.miRCounts==0] <- rnorm(1,mean=1, sd=0.1);
this code made all zero values as 1.13, not random
Thank you, Jim. That clarifies. I am trying to pass this path in a loop and
read the files associated with the path.
Yes the length is 26 where double quotes are counted as single quotes. Let
me try to read the files using the collected path.
Really appreciate it.
Thanks,
Anbu
On Mon, Dec 28, 2
Why do you want to replace '\\' with '\' in the file names? They are
actually single '\' in the character string, but are printing out as '\\'.
see example below:
> x <- 'a\\b'
> x
[1] "a\\b"
> nchar(x)
[1] 3
Jim Holtman
*Data Munger Guru*
*What is the problem that you are
"\" is an escape in R. See ?Quotes for details.
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Mon, Dec 28, 2020 at 12:56 PM Anbu A wrote:
> Hi All,
> I am a
Hi All,
I am able to replace "r" with "x" for the word "Users" just for a test run.
*Code: newlist %>% mutate(.,new_col=str_replace(fpath,"r","x")) *- this
works fine
But when I try to replace "\\" with "\".
*newlist %>% mutate(.,new_col=str_replace(fpath,"\\","\")) *, I get a
prompt ">" to comple
> From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us]
> Sent: Monday, January 8, 2018 4:45 PM
> To: Eric Berger
> Cc: PIKAL Petr ; r-help@r-project.org; Ek Esawi
>
> Subject: Re: [R] Replace NAs in split lists
>
> "Enforce" is overstating it... results will differ
Thank you all. Now everything works. Happy 2018 and beyond
EK
On Sun, Jan 7, 2018 at 10:13 PM, Ek Esawi wrote:
> Hi all--
>
> I stumbled on this problem online. I did not like the solution given
> there which was a long UDF. I thought why cannot split and l/s apply
> work here. My aim is to split
Because you need to separate the instructions with a ; (semi-colon).
Hope this helps
Rui Barradas
Enviado a partir do meu smartphone Samsung Galaxy. Mensagem original
De: Ek Esawi Data: 08/01/2018 16:03 (GMT+00:00)
Para: Jeff Newmiller , r-help@r-project.org Assunto:
Re: [R
I don't get exactly that error message,
> ifelse(is.na(z$Value),z$Value[!is.na(z$Value)][1],z$Value)z})
Error: unexpected symbol in "ifelse(is.na(z$Value),z$Value[!is.na
(z$Value)][1],z$Value)z"
The 'symbol' in "unexpected symbol" refers to a "name" ('z' in this case).
The problem is usually at
OPS! Sorry i did indeed posted the code in HTML; should have known better.
ifelse(is.na(z$Value),z$Value[!is.na(z$Value)][1],z$Value)z})
error. unexpected symbol in sdf2
On Mon, Jan 8, 2018 at 11:44 AM, Jeff Newmiller
wrote:
> I don't know. You seem to be posting in HTML so your code is mangled
I don't know. You seem to be posting in HTML so your code is mangled. Can you
post plain text and use the reprex package to make sure it produces the errorin
a clean R session?
--
Sent from my phone. Please excuse my brevity.
On January 8, 2018 8:03:45 AM PST, Ek Esawi wrote:
>Thank you Jeff.
Thank you Jeff. Your code works, as usual , perfectly. I am just
wondering why if i put the whole code in one line, i get an error
message.
sdf2 <- lapply( sdf, function(z){z$Value
<-ifelse(is.na(z$Value),z$Value[!is.na(z$Value)][1],z$Value)z})
error. unexpected symbol in sdf2
Thanks again
EK
O
>> >3 a ac FALSE 2
>> >4 b aa TRUE 5
>> >5 b ab FALSE 5
>> >
>> >Cheers
>> >Petr
>> >
>> >> -Original Message-
>> >> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf
gt; From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff
> >> Newmiller
> >> Sent: Monday, January 8, 2018 9:13 AM
> >> To: r-help@r-project.org; Ek Esawi
> >> Subject: Re: [R] Replace NAs in split lists
> >>
> >> Upon closer examin
om: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff
>> Newmiller
>> Sent: Monday, January 8, 2018 9:13 AM
>> To: r-help@r-project.org; Ek Esawi
>> Subject: Re: [R] Replace NAs in split lists
>>
>> Upon closer examination I see that you are not using
lp [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff
> Newmiller
> Sent: Monday, January 8, 2018 9:13 AM
> To: r-help@r-project.org; Ek Esawi
> Subject: Re: [R] Replace NAs in split lists
>
> Upon closer examination I see that you are not using the split version of
> df1
Upon closer examination I see that you are not using the split version of
df1 as I usually would, so here is a reproducible example:
#
df1 <- read.table( text=
"ID ID_2 Firist Value
1 a aa TRUE 2
2 a ab FALSENA
3 a ac FALSENA
4 b aa TRUE 5
5 b ab FALSE
Why do you want to modify df1?
Why not just reassemble the parts as a new data frame and use that going
forward in your calculations? That is generally the preferred approach in R so
you can re-do your calculations easily if you find a mistake later.
--
Sent from my phone. Please excuse my bre
wi
> Sent: Monday, January 8, 2018 4:36 AM
> To: r-help@r-project.org
> Subject: Re: [R] Replace NAs in split lists
>
> I just came up with a solution right after i posted the question, but i
> figured
> there must be a better and shorter one.than my solution sdf1[[1]][1,4]<-
>
I just came up with a solution right after i posted the question, but
i figured there must be a better and shorter one.than my solution
sdf1[[1]][1,4]<-lapplyresults[[1]]
sdf1[[2]][1,4]<-lapplyresults[[2]]
EK
On Sun, Jan 7, 2018 at 10:13 PM, Ek Esawi wrote:
> Hi all--
>
> I stumbled on this prob
Hi all--
I stumbled on this problem online. I did not like the solution given
there which was a long UDF. I thought why cannot split and l/s apply
work here. My aim is to split the data frame, use l/sapply, make
changes on the split lists and combine the split lists to new data
frame with the desi
;Bob" "Bob"
[7] "Alex-2002" "Alex-2003" "Alex-2004"
Cheers
Petr
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Marc
> Schwartz
> Sent: Tuesday, March 14, 2017 12:33 AM
> To: Val
&
> On Mar 13, 2017, at 5:53 PM, Val wrote:
>
> HI all,
>
> if first name is Alex then I want concatenate the second column to Alex
> to produce Alex and the second column value
>
> DF1 <- read.table(header=TRUE, text='first YR
> Alex2001
> Bob 2001
> Cory2001
> Cory2002
> Bob
HI all,
if first name is Alex then I want concatenate the second column to Alex
to produce Alex and the second column value
DF1 <- read.table(header=TRUE, text='first YR
Alex2001
Bob 2001
Cory2001
Cory2002
Bob 2002
Bob 2003
Alex2002
Alex2003
Alex2004')
Out
> On Feb 28, 2017, at 8:36 AM, Jeff Newmiller wrote:
>
> For tasks like this, you will probably want to make sure to import the data
> as character data rather than as a factor. E.g.
>
> dat <- read.csv( "myfile.csv", header=FALSE, as.is=TRUE )
>
> You can check what you have with the str()
For tasks like this, you will probably want to make sure to import the data as
character data rather than as a factor. E.g.
dat <- read.csv( "myfile.csv", header=FALSE, as.is=TRUE )
You can check what you have with the str() function.
--
Sent from my phone. Please excuse my brevity.
On Februa
> On Feb 28, 2017, at 3:38 AM, Harshal Athawale
> wrote:
>
> I am new in R.
>
> I have a file. This file contains name of the companies.
> 'data.frame': 494 obs. of 1 variable:
> $ V1: Factor w/ 470 levels "3-d engineering corp",..: 293 134 339 359 143
> 399 122 447 398 384 ...
>
> Problem:
I am new in R.
I have a file. This file contains name of the companies.
'data.frame': 494 obs. of 1 variable:
$ V1: Factor w/ 470 levels "3-d engineering corp",..: 293 134 339 359 143
399 122 447 398 384 ...
Problem: I would like to remove "CO" (As it is the most frequent word). I
would like "C
And here is another.
sub("\\.", " ", "c.t")
Rui Barradas
Em 19-11-2016 01:35, Bert Gunter escreveu:
Well of course. See ?regexp where it says:
"The period . matches any single character."
(Always a good idea to read man pages, although this *is* a complex one)
Setting the fixed argument to
Well of course. See ?regexp where it says:
"The period . matches any single character. "
(Always a good idea to read man pages, although this *is* a complex one)
Setting the fixed argument to TRUE is one way to get what you want
(there are others).
> sub(".", " ", "c.t",fixed=TRUE)
[1] "c t"
Hi, your were close.
This is the solution:
sub("[.]", " ", "c.t")
You need to scape the point, because point has a especial meaning in
regular expressions. Read more on regex...
2016-11-18 19:13 GMT-05:00 John :
> Hi,
>
>Is there any function that replaces a dot with a space? I expect "c t
Hi,
Is there any function that replaces a dot with a space? I expect "c t"
from the output of the second call of function sub, but it did not do so.
> sub("a", "b", "cat")
[1] "cbt"
> sub(".", " ", "c.t")
[1] " .t"
Thanks!
[[alternative HTML version deleted]]
___
Your first replacement in kx changed it to a character vector and
comparisons
of character strings given different results than comparisons of numbers
> kx <- 1:10
> qt <- quantile(kx)
> kx[kx <= qt[2]] <- "DN"
> kx
[1] "DN" "DN" "DN" "4" "5" "6" "7" "8" "9" "10"
> "10" < "6"
[1] TRUE
>
> #
Your goal is fundamentally flawed, since all elements of a vector must be if
the same type.
Create another vector to hold your character information.
kc <- rep( 'NC', length( kx ) )
kc[ kx <= qt[[2]] ] <- 'DN'
kc[ kx >=qt [[4]] ] <- 'UP'
--
Sent from my phone. Please excuse my brevity.
On N
Hi group,
I have a vector of numeric items and I want to replace based on
logical operator (> or <) with 'up', 'down' or 'nochange'
The way I am doing works sometimes and does not work sometime. I dont
understand the problem. In this example, that works for condition DN
first, gets over-written
Your use of HTML email corrupted your example slightly, but I was able to
fix it. Please follow the Posting Guide and set your emails to Plain Text
mode when posting to this mailing list in the future.
Here is one way:
# you have to be careful about mucking with factors
# convert columns to fa
Marine:
Thanks for the reproducible example. I would not have fooled with this
otherwise!
1. First note that your specification that you wish to replace only
those values in col3 and col4 of df1 that don't match with those of
df2 is irrelevant: if you replace those that do match you don't change
Hello,
I have two data frames with different sizes but with the same number of columns.
> df1 <- data.frame(col1 = c(1:6), col2 = c(rep("a", 3), rep("b", 3)), col3 =
> c(rep("AA", 2), rep("BB", 2), rep("CC", 2)), col4=c(1,8,6,9,7,6))
> df1
col1 col2 col3 col4
11a AA1
22
Sidenote:
When you do imputation in this way all your inference (error
estimates, goodness of fit, confidence intervals, etc.) will be wrong
and misleading, as you are creating "information" from nothing.
If this comment is irrelevant, please ignore.
Cheers,
Bert
Bert Gunter
"The trouble with h
Maybe you can use something like this
In this way, almost your proportion of 0, 1 and 2 will be maintained
m <- matrix(sample(c(NA, 0:2), size = 50*100, replace = TRUE), nrow = 50,
ncol = 100)
trunc(prop.table(apply(m, 2, table), 2) * colSums(is.na(m)), 0)
m[is.na(m)] <- unlist(apply(trunc(prop.t
Hello specialist,
I have a matrix in which there are NA,0,1 and 2 in each columns.
I wanna replace NAs with special proportion of 0,1 or 2 !
for example in df<- matric(df, nrow=50, ncol=100)
If in one column the number of NAs = 10 , # of 0=50 , #of 1=25 and # of
2=15
I want to replace 5 of 10 N
Hi Ragia,
If you have read in your data frame with read.table or similar and not
specified stringsAsFactors=FALSE, the two columns will already be
factors. However, unless they both contain the same number of unique
values, the numbers associated with those levels won't be the same.
Probably the ea
> On Mar 8, 2016, at 1:48 PM, Sarah Goslee wrote:
>
> Thanks for the complete reproducible example.
>
> Here's one way to approach the problem; there are many others.
>
> recodeDat <- function(x, invals, outvals) {
> x <- as.character(x)
> invals <- as.character(invals)
> outvals <- as.charact
))
Cheers
Petr
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ragia .
> Sent: Wednesday, March 09, 2016 9:11 AM
> To: r-help@r-project.org
> Subject: [R] replace text by uniqe number
>
> Dear group
> kindly if i had data fra
Dear group
kindly if i had data frame of 2 columns that has repeated URLS ..and want to
replace those urls with ID's for each one so the url will have
unique ID, how can I do this
thanks in advance
e.g otf data
pcworld.com open.itworld.com
pcworld.com storage.itworld.com
salon.com
Thanks for the complete reproducible example.
Here's one way to approach the problem; there are many others.
recodeDat <- function(x, invals, outvals) {
x <- as.character(x)
invals <- as.character(invals)
outvals <- as.character(outvals)
# a loop is the most understandable approach
for(i in seq_a
Hi R Users,
I have been struggling to replace texts in a table by new text. but it
seems crazy as of I am doing it manually in R. I have very big files and
some of the text has to be replaced by another class based on another file
if the name corresponds. I was able to perform following example but
Excerpts from Zahra via R-help's message of 2015-11-02 17:49:01 -0200:
> Hi there,
>
> I am looking for some help replacing missing values in R with the row mean.
> This is survey data and I am trying to impute values for missing variables in
> each set of questions separately using the mean of
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 Jim Lemon
Sent: Monday, November 2, 2015 5:33 PM
To: Zahra
Cc: r-help mailing list
Subject
Hi again,
Small typo in line 5 - should be
replace_NAs<-function(x,group_lab=c("A","B","C")) {
for(lab in group_lab) {
indices<-grep(lab,names(x),fixed=TRUE)
na_indices<-is.na(x[indices])
if(any(na_indices))
x[indices][na_indices]<-rowMeans(x[indices],na.rm=TRUE)
}
return(x)
}
Jim
Hi Zahra,
I can't think of an "apply" function that will do this, but:
Zdf<-read.table(text="ID A1 A2 A3 B1 B2 B3 C1 C2 C3 C4
b 4 5 NA2 NA 4 5 13
NA
c 4 5 1 NA 34 5 13
2
Hi there,
I am looking for some help replacing missing values in R with the row mean.
This is survey data and I am trying to impute values for missing variables in
each set of questions separately using the mean of the scores for the other
questions within that set.
I have a dataset that look
Ok, i will do, thanks for your help.
J
> Subject: RE: [R] Replace NaN with value from the same row
> From: jdnew...@dcn.davis.ca.us
> Date: Sun, 18 Oct 2015 12:55:14 -0700
> To: jonathanrear...@outlook.com
> CC: r-help@r-project.org
>
> You should (re-)read the intro docum
is making a new
>column called 'idx', finds the NaN values and inserts the boolean TRUE
>in the respective cell.
>df[ idx, "mean" ] <- df[ idx, "offset" ] << i am unsure what this
>is doing exactly.
>Jon
>
>
>> Subject: RE: [R] Rep
AM PDT, Jonathan Reardon
wrote:
>How do i send an email in plain text format and not HTML?
>I tried:
>idx <- is.na( df$mean )
>df[ idx, "mean" ] <- df[ idx, "offset" ]
>I got the error message:
>In is.na(df$mean) : is.na() applied to non-(list or ve
Hi everyone,
Ignore my previous post, i realised that the rows and columns i typed into the
email were unreadable, sincere apologies for this.
A simple question, but i cannot figure this out.
I have a data-frame with 4 columns (onset, offset, outcome, mean):
df<-data.frame(onset=c(72071,142598,293
Next time send your email using plain text format rather than HTML so we see
what you saw.
Try
idx <- is.na( df$mean )
df[ idx, "mean" ] <- df[ idx, "offset" ]
BTW there is a commonly-used function called df, so you might improve clarity
by using DF for your temporary data frame name.
---
Hi everyone,
A simple question, but i cannot figure this out.
I have a data-frame with 4 columns (onset, offset, outcome, mean):
onset offset outcome mean8 72071 72503 1 7244615 142598 143030
1NaN30 293729 294161 1 294080
For each 'NaN' in the mean column, i want to r
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",
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
elp [mailto:r-help-boun...@r-project.org] On Behalf Of Kuma
> Raj
> Sent: Monday, March 23, 2015 1:59 PM
> To: r-help@r-project.org
> Subject: [R] Replace a column value on condition
>
> I want to replace column c3 with values from column c2 whenever values
> of column Id are 2.
> On 23-03-2015, at 13:58, Kuma Raj wrote:
>
> I want to replace column c3 with values from column c2 whenever values
> of column Id are 2. In stata I could use replace c3 = c2 if id ==2.
> How could I do that in R?
>
k <- which(df4$id==2)
df4[k,"c3"] <- df4[k,"c2”]
Berend
> Thanks
>
>
>
I want to replace column c3 with values from column c2 whenever values
of column Id are 2. In stata I could use replace c3 = c2 if id ==2.
How could I do that in R?
Thanks
Sample data found below:
> dput(df4)
structure(list(c2 = c(42L, 42L, 47L, 47L, 55L, 55L, 36L, 36L,
61L, 61L), c3 = c(68L, 5
> On 27 Feb 2015, at 16:02 , Duncan Murdoch wrote:
>
> Yes. Indexing with a logical NA is probably a mistake, and this is one
> way to signal it without actually triggering a warning or error.
There are cases where it isn't (usually) a mistake, e.g. pch=c(25,24)[sex],
where it is quite crucia
Thank you very much guys!
On Fri, Feb 27, 2015 at 11:04 AM, William Dunlap wrote:
> You could define functions like
>is.true <- function(x) !is.na(x) & x
>is.false <- function(x) !is.na(x) & !x
> and use them in your selections. E.g.,
> > x <- data.frame(a=1:10,b=2:11,c=c(1,NA,3,NA,5,N
You could define functions like
is.true <- function(x) !is.na(x) & x
is.false <- function(x) !is.na(x) & !x
and use them in your selections. E.g.,
> x <- data.frame(a=1:10,b=2:11,c=c(1,NA,3,NA,5,NA,7,NA,NA,10))
> x[is.true(x$c >= 6), ]
a b c
7 7 8 7
10 10 11 10
Bill Dun
On 27/02/2015 10:27 AM, Dimitri Liakhovitski wrote:
> Thank you very much, Duncan.
> All this being said:
>
> What would you say is the most elegant and most safe way to solve such
> a seemingly simple task?
If you have NA values, test for them explicitly, e.g. your original
x[(x$c<6) | is.na(x$
Thank you very much, Duncan.
All this being said:
What would you say is the most elegant and most safe way to solve such
a seemingly simple task?
Thank you!
On Fri, Feb 27, 2015 at 10:02 AM, Duncan Murdoch
wrote:
> On 27/02/2015 9:49 AM, Dimitri Liakhovitski wrote:
>> So, Duncan, do I understan
On 27/02/2015 9:49 AM, Dimitri Liakhovitski wrote:
> So, Duncan, do I understand you correctly:
>
> When I use x$x<6, R doesn't know if it's TRUE or FALSE, so it returns
> a logical value of NA.
Yes, when x$x is NA. (Though I think you meant x$c.)
> When this logical value is applied to a row,
So, Duncan, do I understand you correctly:
When I use x$x<6, R doesn't know if it's TRUE or FALSE, so it returns
a logical value of NA.
When this logical value is applied to a row, the R says: hell, I don't
know if I should keep it or not, so, just in case, I am going to keep
it, but I'll replace
On 27/02/2015 9:04 AM, Dimitri Liakhovitski wrote:
> I know how to get the output I need, but I would benefit from an
> explanation why R behaves the way it does.
>
> # I have a data frame x:
> x = data.frame(a=1:10,b=2:11,c=c(1,NA,3,NA,5,NA,7,NA,NA,10))
> x
> # I want to toss rows in x that conta
I know how to get the output I need, but I would benefit from an
explanation why R behaves the way it does.
# I have a data frame x:
x = data.frame(a=1:10,b=2:11,c=c(1,NA,3,NA,5,NA,7,NA,NA,10))
x
# I want to toss rows in x that contain values >=6. But I don't want
to toss my NAs there.
subset(x,c
On 2015-02-26 00:33, JS Huang wrote:
Hi,
Here is an implementation. More data are added. An extra column hasRain
is added instead of replacing column Amount.
rain
Year Month Day Amount
1 1950 1 10.0
2 1950 1 2 35.5
3 1950 1 3 17.8
4 1950 1 4 24
Hi,
Here is an implementation. More data are added. An extra column hasRain
is added instead of replacing column Amount.
> rain
Year Month Day Amount
1 1950 1 10.0
2 1950 1 2 35.5
3 1950 1 3 17.8
4 1950 1 4 24.5
5 1950 1 5 12.3
6 1950 1
me tidying up.
HTH
Peter Alspach
-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of smart hendsome
Sent: Thursday, 26 February 2015 11:54 a.m.
To: r-help@r-project.org
Subject: [R] Replace the value with 1 and 0
Hi everyone,
I have this kind of rainfall da
;month')], sum)
will give your final table, but it will need some tidying up.
HTH
Peter Alspach
-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of smart hendsome
Sent: Thursday, 26 February 2015 11:54 a.m.
To: r-help@r-project.org
Subject: [R] Re
Hi everyone,
I have this kind of rainfall dataset:
Year Month Day Amount
1 1950 1 1 0.0
2 1950 1 2 35.5
3 1950 1 3 17.8
4 1950 1 4 24.5
5 1950 1 5 12.3
6 1950 1 6 11.5
7 1950 1 7 5.7
8 1950 1 8 13.2
9 1950 1 9 11.
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
1 - 100 of 452 matches
Mail list logo