[R] replacing a value
Ebert,Timothy Aaron
tebert @end|ng |rom u||@edu
Wed Apr 6 14:30:21 CEST 2022
Excellent.
So Ani's answer to a==20 is different than Jim's answer. Jim's answer has some TRUE and some FALSE while Ani's answer is all FALSE.
I get Jim's answer.
That is the problem, but I don't know how to solve it.
What is str(a)?
Are there any error messages?
What if you close R and restart? Just to be complete, try turning the power off on your computer and restarting the entire system.
Tim
-----Original Message-----
From: R-help <r-help-bounces using r-project.org> On Behalf Of ani jaya
Sent: Wednesday, April 6, 2022 12:18 AM
To: Jim Lemon <drjimlemon using gmail.com>
Cc: r-help <r-help using r-project.org>
Subject: Re: [R] replacing a value
[External Email]
Hello Jim,
Thank you for the try. I am following your step and still have the problem.
But I know for sure now that my R/system is somewhat "broken" or I do not know for sure.
> a
[1] 20.00000 20.00000 14.23756 20.00000 20.00000 20.00000 16.30921
20.00000 20.00000 20.00000
[11] 20.00000 20.00000 20.00000 20.00000 20.00000 14.85909 16.17894
20.00000 20.00000 20.00000
[21] 20.00000 27.64041 20.00000 20.00000 20.00000 20.00000 20.00000
21.98571 20.00000 20.00000
[31] 20.00000 20.00000
> a==20
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [17] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
> a[a==20]<-0
> a
[1] 20.00000 20.00000 14.23756 20.00000 20.00000 20.00000 16.30921
20.00000 20.00000 20.00000
[11] 20.00000 20.00000 20.00000 20.00000 20.00000 14.85909 16.17894
20.00000 20.00000 20.00000
[21] 20.00000 27.64041 20.00000 20.00000 20.00000 20.00000 20.00000
21.98571 20.00000 20.00000
[31] 20.00000 20.00000
On Wed, Apr 6, 2022 at 12:16 PM Jim Lemon <drjimlemon using gmail.com> wrote:
>
> Hi Ani,
> It seems to work for me:
>
> a<-c(20, 20, 14.2375646029948, 19.9999999999999, 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.00000 0.00000 14.23756 20.00000 0.00000 0.00000 16.30921
> 0.00000 [9] 0.00000 0.00000 0.00000 0.00000 0.00000 0.00000
> 0.00000 14.85909 [17] 16.17894 0.00000 0.00000 0.00000 0.00000
> 27.64041 0.00000 0.00000 [25] 0.00000 0.00000 0.00000 21.98571
> 0.00000 0.00000 0.00000 0.00000
>
> Notice that it didn't make 19.99999999999999 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 <gaaauul using gmail.com> wrote:
> >
> > Dear R-Help,
> >
> > I try to change a specific value here by following these:
> >
> > https://urldefense.proofpoint.com/v2/url?u=https-3A__www.journaldev.
> > com_39695_replace-2Din-2Dr&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQ
> > h2kVeAsRzsn7AkP-g&m=TACLY8J-wKY5Wmh5GANOzGxKC-MKX-FtV6O1IhiR_evXimgt
> > xfQs8N6uI_OjKech&s=JHdEmtV2QpU0x5tkgSoD4ioUdH1s_YEFqBPMtjP2aXY&e=
> > https://urldefense.proofpoint.com/v2/url?u=https-3A__stackoverflow.c
> > om_questions_5824173_replace-2Da-2Dvalue-2Din-2Da-2Ddata-2Dframe-2Db
> > ased-2Don-2Da-2Dconditional-2Dif-2Dstatement&d=DwICAg&c=sJ6xIWYx-zLM
> > B3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=TACLY8J-wKY5Wmh5GANOzGxKC-MKX-
> > FtV6O1IhiR_evXimgtxfQs8N6uI_OjKech&s=Ret9j4R6Dg4DjrSq1DKCJcVkJx5D0fj
> > zUgUb6NjvrBE&e=
> > https://urldefense.proofpoint.com/v2/url?u=https-3A__stackoverflow.c
> > om_questions_54615462_how-2Dto-2Dreplace-2Dcertain-2Dvalues-2Din-2Da
> > -2Dspecific-2Drows-2Dand-2Dcolumns-2Dwith-2Dna-2Din-2Dr&d=DwICAg&c=s
> > J6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=TACLY8J-wKY5Wmh5GAN
> > OzGxKC-MKX-FtV6O1IhiR_evXimgtxfQs8N6uI_OjKech&s=KW2vnxswrucdFsa3bWaB
> > faOQg-JXPhqYouEuONN-GqM&e=
> > ..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.9999999999999, 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 using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_ma
> > ilman_listinfo_r-2Dhelp&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2k
> > VeAsRzsn7AkP-g&m=TACLY8J-wKY5Wmh5GANOzGxKC-MKX-FtV6O1IhiR_evXimgtxfQ
> > s8N6uI_OjKech&s=d3cMYTtmc68ekAgzW4KSEq4vJ5NbfzxlNi5yLvWIgK0&e=
> > PLEASE do read the posting guide
> > https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.
> > org_posting-2Dguide.html&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2
> > kVeAsRzsn7AkP-g&m=TACLY8J-wKY5Wmh5GANOzGxKC-MKX-FtV6O1IhiR_evXimgtxf
> > Qs8N6uI_OjKech&s=ZD6N8cPoUe4KKw4XqS0wC1YvfUzA_EnM0cZ3CYfr4GI&e=
> > and provide commented, minimal, self-contained, reproducible code.
______________________________________________
R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see https://urldefense.proofpoint.com/v2/url?u=https-3A__stat.ethz.ch_mailman_listinfo_r-2Dhelp&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=TACLY8J-wKY5Wmh5GANOzGxKC-MKX-FtV6O1IhiR_evXimgtxfQs8N6uI_OjKech&s=d3cMYTtmc68ekAgzW4KSEq4vJ5NbfzxlNi5yLvWIgK0&e=
PLEASE do read the posting guide https://urldefense.proofpoint.com/v2/url?u=http-3A__www.R-2Dproject.org_posting-2Dguide.html&d=DwICAg&c=sJ6xIWYx-zLMB3EPkvcnVg&r=9PEhQh2kVeAsRzsn7AkP-g&m=TACLY8J-wKY5Wmh5GANOzGxKC-MKX-FtV6O1IhiR_evXimgtxfQs8N6uI_OjKech&s=ZD6N8cPoUe4KKw4XqS0wC1YvfUzA_EnM0cZ3CYfr4GI&e=
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list