Re: [R] replacing a value

2022-04-05 Thread Jim Lemon
Hi Ani,
It seems to work for me:

 a<-c(20, 20, 14.2375646029948, 19.9, 20, 20, 16.3092078677214,
20, 20, 20, 20, 20, 20, 20, 20, 14.8590932408795, 16.178935255298,
20, 20, 20, 20, 27.6404077886079, 20, 20, 20, 20, 20, 21.9857063037444,
20, 20, 20, 20)
> a==20
[1]  TRUE  TRUE FALSE FALSE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE
[13]  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE
[25]  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE
> a[a==20]<-0
> a
[1]  0.0  0.0 14.23756 20.0  0.0  0.0 16.30921  0.0
[9]  0.0  0.0  0.0  0.0  0.0  0.0  0.0 14.85909
[17] 16.17894  0.0  0.0  0.0  0.0 27.64041  0.0  0.0
[25]  0.0  0.0  0.0 21.98571  0.0  0.0  0.0  0.0

Notice that it didn't make 19.99 equal to 20, but did
round it up when printing the result. How do you know that it failed?

Jim

On Wed, Apr 6, 2022 at 12:48 PM ani jaya  wrote:
>
> Dear R-Help,
>
> I try to change a specific value here by following these:
>
> https://www.journaldev.com/39695/replace-in-r
> https://stackoverflow.com/questions/5824173/replace-a-value-in-a-data-frame-based-on-a-conditional-if-statement
> https://stackoverflow.com/questions/54615462/how-to-replace-certain-values-in-a-specific-rows-and-columns-with-na-in-r
> ..and many more
>
> however, it is not change anything. I believe it "should" be easy but
> I think I am missing something. I am afraid it is my system that has a
> problem but restarting r is not solve the problem.
> I just want to change 20 to 0 in my data.
>
> > dput(a)
> c(20, 20, 14.2375646029948, 19.9, 20, 20, 16.3092078677214,
> 20, 20, 20, 20, 20, 20, 20, 20, 14.8590932408795, 16.178935255298,
> 20, 20, 20, 20, 27.6404077886079, 20, 20, 20, 20, 20, 21.9857063037444,
> 20, 20, 20, 20)
>
> what I did:
> a[a==20]<-0 #fail
> a<-replace(a,a==20,0) #fail
> a[which(a==20)]<-0 #fail
>
> > sessionInfo()
> R version 4.1.2 (2021-11-01)
> Platform: x86_64-w64-mingw32/x64 (64-bit)
> Running under: Windows 10 x64 (build 19043)
>
> Matrix products: default
>
> locale:
> [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252
> [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
> system code page: 949
>
> Best,
> Ani
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Replacing cretin value in a file

2012-05-13 Thread Jonsson
Dear All,

I am trying to replace a value of 528.8933 to - in my file

t- file(C:\\Users\\Amin\\Desktop\\1999n_Resample11.img, rb)
e=readBin(t, double(), size=4,n=720*360, signed=TRUE)
e[e != -] - e[e != -]*0.0099 + 477.65 -273.15
##worked well and values heve been calculated
e[e == 528.8933] - -## no changes made to
528.8933

any suggestions please


--
View this message in context: 
http://r.789695.n4.nabble.com/Replacing-cretin-value-in-a-file-tp4629840.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Replacing cretin value in a file

2012-05-13 Thread Jim Holtman
FAQ 7.31

Sent from my iPad

On May 13, 2012, at 7:52, Jonsson amen.alya...@bordeaux.inra.fr wrote:

 Dear All,
 
 I am trying to replace a value of 528.8933 to - in my file
 
 t- file(C:\\Users\\Amin\\Desktop\\1999n_Resample11.img, rb)
 e=readBin(t, double(), size=4,n=720*360, signed=TRUE)
 e[e != -] - e[e != -]*0.0099 + 477.65 -273.15
 ##worked well and values heve been calculated
 e[e == 528.8933] - -## no changes made to
 528.8933
 
 any suggestions please
 
 
 --
 View this message in context: 
 http://r.789695.n4.nabble.com/Replacing-cretin-value-in-a-file-tp4629840.html
 Sent from the R help mailing list archive at Nabble.com.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Replacing cretin value in a file

2012-05-13 Thread Jonsson
Dear Jim,

You may forget to add your suggestions because what I see is just my post

--
View this message in context: 
http://r.789695.n4.nabble.com/Replacing-cretin-value-in-a-file-tp4629840p4629843.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Replacing cretin value in a file

2012-05-13 Thread David Winsemius


On May 13, 2012, at 8:12 AM, Jonsson wrote:


Dear Jim,

You may forget to add your suggestions because what I see is just my  
post


The suggestion was to read the referenced FAQ.


PLEASE do read the posting guide http://www.R-project.org/posting-guide.html


And while you are referencing the FAQ from the R help pages, you might  
also follow the link and read the Posting Guide. It will explain why  
including context is requested. Most people do not want to use Nabble  
and many of us somewhat annoyed that Nabble users seem to expect us to  
use it.


--

David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Replacing cretin value in a file

2012-05-13 Thread Jonsson
Dear All, 

 I am trying to replace a value of 528.8933 to - in my file 

 t- file(C:\\Users\\Amin\\Desktop\\1999n_Resample11.img, rb) 
e=readBin(t, double(), size=4,n=720*360, signed=TRUE) 
 e[e != -] - e[e != -]*0.0099 + 477.65 -273.15  

 This code given above would read a binary file . Then It would do some
clculations to  e.  That worked well. I opend the file again in order to
look at the resultsand I found weird numbers ( 528.8933).

I then used this  line  e[e == 528.8933] - -to replace
the value of 528.8933  by -. I got no errors but when I looked again at
the values, I found them as they were(528.8933 is still there) 
any idea on how to replace a value by another value?Thanks in advance


--
View this message in context: 
http://r.789695.n4.nabble.com/Replacing-cretin-value-in-a-file-tp4629840p4629846.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Replacing cretin value in a file

2012-05-13 Thread David Winsemius


On May 13, 2012, at 9:08 AM, Jonsson wrote:


Dear All,

I am trying to replace a value of 528.8933 to - in my file

t- file(C:\\Users\\Amin\\Desktop\\1999n_Resample11.img, rb)
e=readBin(t, double(), size=4,n=720*360, signed=TRUE)
e[e != -] - e[e != -]*0.0099 + 477.65 -273.15

This code given above would read a binary file . Then It would do some
clculations to  e.  That worked well. I opend the file again in  
order to

look at the resultsand I found weird numbers ( 528.8933).

I then used this  line  e[e == 528.8933] - -to  
replace
the value of 528.8933  by -. I got no errors but when I looked  
again at

the values, I found them as they were(528.8933 is still there)
any idea on how to replace a value by another value?Thanks in advance


From memory  ... since you have not yet learned to include context.  
You were advised to read the FAQ ... item 7.31.


Perhaps this example will help.

 x - 7* round(528.8933/7, 6)

 x== 528.8933
[1] FALSE
 x
[1] 528.8933



PLEASE do read the posting guide http://www.R-project.org/posting-guide.html


--

David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Replacing cretin value in a file

2012-05-13 Thread Berend Hasselman

On 13-05-2012, at 15:08, Jonsson wrote:

 Dear All, 
 
 I am trying to replace a value of 528.8933 to - in my file 
 
 t- file(C:\\Users\\Amin\\Desktop\\1999n_Resample11.img, rb) 
 e=readBin(t, double(), size=4,n=720*360, signed=TRUE) 
 e[e != -] - e[e != -]*0.0099 + 477.65 -273.15  
 
 This code given above would read a binary file . Then It would do some
 clculations to  e.  That worked well. I opend the file again in order to
 look at the resultsand I found weird numbers ( 528.8933).
 
 I then used this  line  e[e == 528.8933] - -to replace
 the value of 528.8933  by -. I got no errors but when I looked again at
 the values, I found them as they were(528.8933 is still there) 
 any idea on how to replace a value by another value?Thanks in advance
 

Please read the R FAQ section 7.31  Why doesn't R think these numbers are 
equal?

http://cran.r-project.org/faqs.html
http://cran.r-project.org/doc/FAQ/R-FAQ.html

Berend

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Replacing cretin value in a file

2012-05-13 Thread Ken Hutchison
Perhaps you are in the first circle of the R Inferno?
   Ken Hutchison



On May 13, 2012, at 9:31 AM, Berend Hasselman b...@xs4all.nl wrote:

 
 On 13-05-2012, at 15:08, Jonsson wrote:
 
 Dear All, 
 
 I am trying to replace a value of 528.8933 to - in my file 
 
 t- file(C:\\Users\\Amin\\Desktop\\1999n_Resample11.img, rb) 
 e=readBin(t, double(), size=4,n=720*360, signed=TRUE) 
 e[e != -] - e[e != -]*0.0099 + 477.65 -273.15  
 
 This code given above would read a binary file . Then It would do some
 clculations to  e.  That worked well. I opend the file again in order to
 look at the resultsand I found weird numbers ( 528.8933).
 
 I then used this  line  e[e == 528.8933] - -to replace
 the value of 528.8933  by -. I got no errors but when I looked again at
 the values, I found them as they were(528.8933 is still there) 
 any idea on how to replace a value by another value?Thanks in advance
 
 
 Please read the R FAQ section 7.31  Why doesn't R think these numbers are 
 equal?
 
 http://cran.r-project.org/faqs.html
 http://cran.r-project.org/doc/FAQ/R-FAQ.html
 
 Berend
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Replacing a value in a dataframe

2011-11-30 Thread arunkumar1111
hi

I have data like this in a dataframe

Var  Value Cheque
X140FALSE
X220FALSE
X328TRUE

I want to replace it FLASE  with 0 and TRUE with 1. 

is there any method by which i can do without using LOOP

--
View this message in context: 
http://r.789695.n4.nabble.com/Replacing-a-value-in-a-dataframe-tp4122188p4122188.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Replacing a value in a dataframe

2011-11-30 Thread Uwe Ligges



On 30.11.2011 09:16, arunkumar wrote:

hi

I have data like this in a dataframe

Var  Value Cheque
X140FALSE
X220FALSE
X328TRUE

I want to replace it FLASE  with 0 and TRUE with 1.

is there any method by which i can do without using LOOP



dataframe$Cheque - as.integer(Cheque)

Uwe Ligges




--
View this message in context: 
http://r.789695.n4.nabble.com/Replacing-a-value-in-a-dataframe-tp4122188p4122188.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Replacing a value in a dataframe

2011-11-30 Thread Bert Gunter
er... Uwe, shouldn't that be, e.g.

dataframe$Cheque - as.integer(dataframe$Cheque)

## or building on Rolf's suggestion

dataframe - within(dataframe, Cheque - as.integer(Cheque))

While I am at it, is there any practical difference in efficiency
between these two approaches?

-- Bert


2011/11/30 Uwe Ligges lig...@statistik.tu-dortmund.de:


 On 30.11.2011 09:16, arunkumar wrote:

 hi

 I have data like this in a dataframe

 Var  Value Cheque
 X1    40    FALSE
 X2    20    FALSE
 X3    28    TRUE

 I want to replace it FLASE  with 0 and TRUE with 1.

 is there any method by which i can do without using LOOP



 dataframe$Cheque - as.integer(Cheque)

 Uwe Ligges



 --
 View this message in context:
 http://r.789695.n4.nabble.com/Replacing-a-value-in-a-dataframe-tp4122188p4122188.html
 Sent from the R help mailing list archive at Nabble.com.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Replacing a value in a dataframe

2011-11-30 Thread Uwe Ligges



On 30.11.2011 12:26, Bert Gunter wrote:

er... Uwe, shouldn't that be, e.g.

dataframe$Cheque- as.integer(dataframe$Cheque)



Sure, thanks.


## or building on Rolf's suggestion

dataframe- within(dataframe, Cheque- as.integer(Cheque))

While I am at it, is there any practical difference in efficiency
between these two approaches?


Well, just profile it. The latter has some overhead, of course:

 d - data.frame(a=c(TRUE, FALSE))
 system.time(for(i in 1:1e4) {d - data.frame(a=c(TRUE, FALSE)); d$a - 
as.integer(d$a)})
 system.time(for(i in 1:1e4) {d - data.frame(a=c(TRUE, FALSE)); d - 
within(d, a - as.integer(a))})



Uwe Ligges




-- Bert


2011/11/30 Uwe Liggeslig...@statistik.tu-dortmund.de:



On 30.11.2011 09:16, arunkumar wrote:


hi

I have data like this in a dataframe

Var  Value Cheque
X140FALSE
X220FALSE
X328TRUE

I want to replace it FLASE  with 0 and TRUE with 1.

is there any method by which i can do without using LOOP




dataframe$Cheque- as.integer(Cheque)

Uwe Ligges




--
View this message in context:
http://r.789695.n4.nabble.com/Replacing-a-value-in-a-dataframe-tp4122188p4122188.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.






__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.