Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8723707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:41:20+00:00 2026-06-13T07:41:20+00:00

I am using reshape2 package to shape my data and use it for t-test.

  • 0

I am using reshape2 package to shape my data and use it for t-test. For me it is easier to visualize the data in separate columns. I have three treatment combinations where “wat” is nested within “spp” and “ins” is nested within water. My demo table contains 3 response variable namely “tyr”, “esc” and “esc_R”. I would be interested in seeing how ins influence response -> “tyr” in “spp” -> Bl, with treatment “wat” -> High (just an example).

Here is my data:
demo.data

## Use orderBy function to sort data
library(doBy)
demo <- orderBy(~spp+wat+ins, data = demo)
## Create an unique data frame for a specific variable
df.bl.ins.1 <- demo[demo$spp == "Bl", c(1:3, 4)]
df.bl.ins.2 <- df.bl.ins.1[df.bl.ins.1$wat == "High", ]

And then I am having trouble executing dcast function.

df.bl.ins.tmp <- dcast(df.bl.ins.2, spp + wat ~ ins, value.var = "tyr")

I have found interesting information in the following threads

  1. Dason’s suggestion – which works really well with ToothGrowth demo dataset. Unfortunately, when the table has multiple treatments (more than 2) the solution did not remain simple. I agree with Maiasaura’s suggestions that creating an unique variable is the key to this problem. However, I am having hard time understanding what function(x) does or how to use it in my table.

Any help in this regard is much appreciated.

In addition, if you have alternative suggestions to do t-test without manipulating the original data frame (demo), I will be excited to hear about it.

Thanks in advance.

Edit
Here is what I am expecting, for “tyr”. In the following format I desire to compare “No” vs. “Yes” using a t-test.

spp wat ins No  Yes
Bl  High    No  0.3036  0.1987
Bl  High    No  0.2577  0.1112
Bl  High    No  NA  0.199
Bl  High    No  0.3299  0.1886
Bl  High    No  0.3301  0.2332
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:41:21+00:00Added an answer on June 13, 2026 at 7:41 am

    Perhaps I don’t understand exactly what you want to do, but I think you could run linear regression directly on your data. In this way, you could do t-tests on whether the coefficients of your model were zero or not. I think this might suffice, and serve also to tease apart the effects of each of your independent variables. Here is an example:

    summary(lm(tyr~spp+wat+ins,data=read.table('http://pastebin.com/raw.php?i=sR2MvBBA')))
    Coefficients:
                 Estimate Std. Error t value Pr(>|t|)    
    (Intercept)  0.286386   0.016500  17.356  < 2e-16 ***
    sppMan      -0.159514   0.015811 -10.089  1.3e-11 ***
    watLow      -0.005501   0.015858  -0.347 0.730861    
    insYes      -0.066741   0.015858  -4.209 0.000185 ***
    

    This will get you a t test for just the groups that you showed in your example:

    t.test(tyr~ins,data=df[df$spp=='Bl' & df$wat=='High',])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert some data from long to wide using the reshape2 package,
In R, I have a data frame with columns for Seat (factor), Party (factor)
I'm using reshape in R to compute aggregate statistics over columns of a data.frame.
I'm using the quantmod package to import financial series data from Yahoo. library(quantmod) getSymbols(^GSPC)
I'm usually using reshape package to aggregate some data (d'uh), usually with plyr ,
After using sapply(data, unlist), I have what I think is a matrix of vectors
I am manipulating a data frame using the reshape package. When using the melt
I'm using reshape in R to compute aggregate statistics over columns of a data.frame.
Suppose (to simplify) I have a table containing some control vs. treatment data: Which,
I have an array representing hourly temperature data, and want to compute daily maxima

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.