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

  • Home
  • SEARCH
  • 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 9145703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:34:49+00:00 2026-06-17T10:34:49+00:00

I have a dataframe that looks like this: step var1 score1 score2 1 a

  • 0

I have a dataframe that looks like this:

step  var1  score1  score2
1      a    0        0
2      b    1        1
3      d    1        1
4      e    0        0
5      g    0        0
1      b    1        1
2      a    1        0
3      d    1        0
4      e    0        1
5      f    1        1
1      g    0        1
2      d    1        1
etc.

Because I need to correlate variabeles a-g (their scores are in score1) with score2 in only step 5 I think i need to schange my dataset into this first:

a   b   c   d   e   f   g   score2_step5
0   1       1   0       0   0
1   1       1   0   1       1
            1           0 
etc.

I am pretty sure that the Reshape package should be able to help me to do the job, but I haven’t been able to make it work yet.
Can anyone help me? Many thanks in advance!

  • 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-17T10:34:50+00:00Added an answer on June 17, 2026 at 10:34 am

    Here’s another version. In case there is no step = 5, the value for score2_step = 0. Assuming your data.frame is df:

    require(reshape2)
    out <- do.call(rbind, lapply(seq(1, nrow(df), by=5), function(ix) {
        iy <- min(ix+4, nrow(df))
        df.b <- df[ix:iy, ]
        tt <- dcast(df.b, 1 ~ var1, fill = 0, value.var = "score1", drop=F)
        tt$score2_step5 <- 0
        if (any(df.b$step == 5)) {
            tt$score2_step5 <- df.b$score2[df.b$step == 5]
        }
        tt[,-1]
    }))
    
    > out
       a b d e f g score2_step5
    2  0 1 1 0 0 0            0
    21 1 1 1 0 1 0            1
    22 0 0 1 0 0 0            0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dataframe that looks like this: person n start end 1 sam
I have a dataframe that looks like this DF: V1 V2 V3 V4 V5
I have a pandas dataframe object that looks like this: one two three four
I'm working in R. I have a dataframe, df that looks like this: >
I have a csv that looks like Deamon,Host,1:2:4,aaa.03 Pixe,Paradigm,1:3:5,11.us I need to read this
I have a dataframe that looks like this: data median min max no_of_threads 2.33
I have a dataframe that looks like this: created_at actor_attributes_email type 3/11/12 7:28 jeremy@asynk.ch
I have a dataframe that looks like this: <class 'pandas.core.frame.DataFrame'> DatetimeIndex: 2016910 entries, 2009-01-02
I have a current DataFrame that looks like this: DATETIME MEAS_AVG TARG_MIN TARG_AVG TARG_MAX
Suppose I have an R dataframe that looks like this, where end.group signifies the

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.