Bioequivalence and Bioavailability Forum

Main page Policy/Terms of Use Abbreviations Latest Posts

 Log-in |  Register |  Search

Back to the forum  Query: 2017-11-18 13:01 CET (UTC+1h)
 
ElMaestro
Hero

Denmark,
2016-09-21 12:59

Posting: # 16657
Views: 2,254
 

 Smart recoding of vector values [R for BE/BA]

Hi all, especially the R experts out there,

I have a vector like
a=c(1,1,2,2,3,5,5,6,6,7,8,8,9,9)
and I would like to rename/reorder/resomething this vector so that
a=c(1,1,2,2,3,4,4,5,5,6,7,7,8,8)

They are actually factor levels.

So far I took a look at reorder, rank, and sort and googled around but I am not really getting anywhere. I have written a clumsy function that does the trick, but I am sure this can be achieved with a one-liner somehow.

Anyone able to tell how?

Thanks a lot in advance and have a great day.:-)

I could be wrong, but…


Best regards,
ElMaestro

No, I still don't believe much in the usefulness of IVIVCs for OIPs when it comes to picking candidate formulations for the next trial. This is not the same as saying I don't believe in IVIVCs.
d_labes
Hero

Berlin, Germany,
2016-09-21 13:32

@ ElMaestro
Posting: # 16659
Views: 1,840
 

 Vectorized if

Dear öberster größter Meister!

» I have a vector like
» a=c(1,1,2,2,3,5,5,6,6,7,8,8,9,9)
» and I would like to rename/reorder/resomething this vector so that
» a=c(1,1,2,2,3,4,4,5,5,6,7,7,8,8)

Vectorized if comes to rescue.
a <- ifelse(a<4, a, a-1)

Hope this helps and matches your problem.

BTW: Hardcore Rusers never use = for assignments :no:

Regards,

Detlew
mittyri
Senior

Russia,
2016-09-21 13:34

@ ElMaestro
Posting: # 16660
Views: 1,828
 

 Smart recoding of vector values

Hi ElMaestro,

my noob version
a <- c(1,1,2,2,3,5,5,6,6,7,8,8,9,9)
a <- as.integer(factor(a, unique(a)))

Kind regards,
Mittyri
ElMaestro
Hero

Denmark,
2016-09-21 14:02
(edited by ElMaestro on 2016-09-21 14:14)

@ mittyri
Posting: # 16661
Views: 1,821
 

 Smart recoding of vector values

Dear Mittyri and d_labes,


» my noob version
» a <- c(1,1,2,2,3,5,5,6,6,7,8,8,9,9)
» a <- as.integer(factor(a, unique(a)))

Thanks a lot to both of you. You guys are nothing short of geniuses.
I think Mityri's example is better. The example that I gave had one single missing integer, but there are frequently plenty, like
a=c(1,1,2,2,3,5,5,6,6,7,8,8,12,12, 13,13,14,16,16) etc. I apologise I should have written that.



a<-5
if(2*a<-<-10) cat("Yah, that '<-' business is very neat.\n")
:-D:-D:-D

I could be wrong, but…


Best regards,
ElMaestro

No, I still don't believe much in the usefulness of IVIVCs for OIPs when it comes to picking candidate formulations for the next trial. This is not the same as saying I don't believe in IVIVCs.
d_labes
Hero

Berlin, Germany,
2016-09-21 15:27

@ mittyri
Posting: # 16662
Views: 1,791
 

 Smart recoding of vector values

Dear mittyri,

» a <- c(1,1,2,2,3,5,5,6,6,7,8,8,9,9)
» a <- as.integer(factor(a, unique(a)))

Smart :ok:

Regards,

Detlew
Back to the forum Activity
 Thread view
Bioequivalence and Bioavailability Forum | Admin contact
17,481 Posts in 3,743 Threads, 1,083 registered users;
34 users online (1 registered, 33 guests).

I have had my results for a long time:
but I do not yet know how I am to arrive
at them.    Carl Friedrich Gauss

The BIOEQUIVALENCE / BIOAVAILABILITY FORUM is hosted by
BEBAC Ing. Helmut Schütz
XHTML/CSS RSS Feed