[R] Coding help for data frame.

Sarah Goslee @@r@h@go@|ee @end|ng |rom gm@||@com
Thu Mar 21 16:20:59 CET 2019


Please also copy the R-help email list when you reply.

On Thu, Mar 21, 2019 at 10:05 AM Anaanthan Pillai
<anaanthanpillai using gmail.com> wrote:
>
> The hypothetical data is about drug x and drug y both we assume as diabetic drug which can reduce hbaic level (sugar level)
>
> Currently I have a data frame of 3X50, whereby the columns is (ID, drug x’s hba1c reduction, drug y’s hba1c reduction)
>
> I want to reaarrange the data into ID, type of drugs (x or y) and their  corresponding hba1c level.

Probably you need the reshape2 package. Can you provide an example of
what you expect the resulting data frame to look like? I'm assuming
that your sample data is the starting point.

Or do you simply need to rbind the two columns together?

Sarah


> Anand
>
> Begin forwarded message:
>
> From: Sarah Goslee <sarah.goslee using gmail.com>
> Subject: Re: [R] Coding help for data frame.
> Date: 21 March 2019 at 9:56:43 PM MYT
> To: Anaanthan Pillai <anaanthanpillai using gmail.com>
> Cc: r-help <r-help using r-project.org>
>
> I'm sorry, I don't understand what you're trying to do with your
> hypothetical data.
>
> Can you expand on what your question is?
>
> Sarah
>
> On Thu, Mar 21, 2019 at 9:54 AM Anaanthan Pillai
> <anaanthanpillai using gmail.com> wrote:
>
>
> Good day,
>
> #I’ve created hypothetical data for drug X and drug Y whereby both drug have the ability to have HbA1c reduction.
>
> set.seed(10)
> drugx= rnorm(50, mean = 0.1, sd=0.02)
>
> set.seed(11)
> drugy= rnorm(50, mean=0.15, sd=0.03)
>
> #And created a data frame, compare drugs (comdrug) of 50 patients for each drug.
>
> comdrug= data.frame("ID"=c(1:50), "DrugX"=drugx, "DrugY"=drugy)
>
> # whereby the data would look like this
>
> head(comdrug)
>
> head(comdrug)
>
>  ID      DrugX     DrugY
> 1  1 0.10037492 0.1322691
> 2  2 0.09631495 0.1507978
> 3  3 0.07257339 0.1045034
> 4  4 0.08801665 0.1091204
> 5  5 0.10589090 0.1853547
> 6  6 0.10779589 0.1219755
>
> Is there anyway of coding if I could arrange like this?
>
>

-- 
Sarah Goslee (she/her)
http://www.numberwright.com



More information about the R-help mailing list