[R] Help with a setting some values of a df vector to 0 but not all values

Bill Poling B|||@Po||ng @end|ng |rom ze||@@com
Thu Apr 18 14:39:02 CEST 2019


Good morning.

#RStudio Version 1.1.456
sessionInfo()
#R version 3.5.3 (2019-03-11)
#Platform: x86_64-w64-mingw32/x64 (64-bit)
#Running under: Windows >= 8 x64 (build 9200)

I have a df column that looks like the below.

#68 ID's including the 0 value

I want to set all the values to 0 with the exception of 5 which are c(1565, 1569, 1674, 415, 1564))

I realize its basic but the routine eludes me, I have googled and there are plenty of
urls for setting to NA, etc.. but nothing I found, yet, where it is a subset routine excluding a few values.

I expect the routine would be something like --

set df1$ClaimManagerID = 0 where df$ClaimManagerID NOT IN c(1565,1569,1674,415,1564)

str(df$ClaimManagerID)
 int [1:18015] 1558 0 1565 1565 1565 1565 1565 0 1565 1565 ...

|ClaimManagerID |       cnt|       pct|   cum_pct|
|:--------------           |--------:|--------       -:|--------       -:|
|1565                      | 11412| 0.6334721| 0.6334721|
|0                            |  6120| 0.3397169| 0.9731890|
|1569                     |    162| 0.0089925| 0.9821815|
|1674                     |      25| 0.0013877| 0.9835692|
|415                       |      21| 0.0011657| 0.9847349|
|1564                     |      20| 0.0011102| 0.9858451|
|234                       |      19| 0.0010547| 0.9868998|
|521                       |      17| 0.0009437| 0.9878435|

etc....= 68 ID's

Thank you for any help.

WHP



Confidentiality Notice This message is sent from Zelis. ...{{dropped:13}}



More information about the R-help mailing list