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 627121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:29:39+00:00 2026-05-13T19:29:39+00:00

Say I have a data frame with the contents: Trial Person 1 John 2

  • 0

Say I have a data frame with the contents:

Trial Person 
1     John   
2     John   
3     John   
4     John
1     Bill 
2     Bill
3     Bill
4     Bill

and I want to transform this to

Trial Person Day
1     John   1
2     John   1
3     John   2
4     John   2
1     Bill   1
2     Bill   1
3     Bill   2
4     Bill   2

I can very easily make it

Trial Person Day
1     John   TRUE
2     John   TRUE
3     John   FALSE
4     John   FALSE
1     Bill   TRUE
2     Bill   TRUE
3     Bill   FALSE
4     Bill   FALSE

by doing d$day=d$trial<3 but how can I get to what I want?

  • 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-05-13T19:29:39+00:00Added an answer on May 13, 2026 at 7:29 pm

    If you want to be explicit with the assignment (and hard-coding the cutoff of 3), you can use

    d$Day <- ifelse(d$trial<3, 1, 2)
    

    This is a bit more transparent. Otherwise, as you discovered, doing an arithmetic operation will convert the logical value to numeric. You can do it yourself by using as.numeric or as.integer:

    as.integer(FALSE)  #0
    as.integer(TRUE)   #1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a data frame with the contents: Trial Person Time 1 John
Let's say i have this json data. How to transform the tags to a
Let's say I have a data frame looking like this: Value1 Value2 1 543
Let's say I have a data frame with numerical values like this AA01.AVG_Beta AA02.AVG_Beta
Say I have this data, (df <- data.frame( col1 = c('My','Your','His','Thir'), col2 = c('Cat','Dog','Fish','Dog')))
Let's say I have a data frame, like this: df <- data.frame( variable =
Let's say I have a data.frame like this: molten <- data.frame( Var1 = factor(
Let's say you have this data in R, and you want to post a
Say I have a data frame with two factors in there and I want
I have data frame with two column say a and b now I want

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.