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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:48:11+00:00 2026-06-18T10:48:11+00:00

I am doing clickstream logfile summaries with raw row input format UID=character, Win/Lose=Boolean. The

  • 0

I am doing clickstream logfile summaries with raw row input format UID=character, Win/Lose=Boolean. The output summary I want to create is of form row UID, sumWin, sumLose. I have used table to get part of what I want, but I am having trouble working out the right syntax for extracting the factor labels from a table result for use in the summary df. The example below builds up a tiny test case and shows where I get stuck: I cannot get at the factor labels from the table result. (Of course, you think there’s a much better way of going about the whole thing – that would clearly be hugely useful too!)

I am still having trouble with formatting in the editor here – clearly that’s a question I need to ask next…!

foo <- data.frame(Uid=character(4), Win=logical(4), stringsAsFactors=FALSE)  
  foo$Uid <- c("UidA", "UidB", "UidA", "UidC")  
  foo$Win <- c(FALSE, TRUE, TRUE, FALSE)  
  #display foo  
  foo  
   Uid   Win  
1 UidA FALSE  
2 UidB  TRUE  
3 UidA  TRUE  
4 UidC FALSE  

  # my desired summary df is, for each UID: NWin (foo$Win=TRUE), NRunUp (foo$Win=FALSE)   
  # here I initialise a holder for it  
  fooNUniques <- length(unique(foo$Uid))  
  fooSummary <- data.frame(Uids=character(fooNUniques),NWins=numeric(fooNUniques),NRunUps=numeric(fooNUniques))   
  fooSummary

  Uids NWins NRunUps

1          0       0  
2          0       0  
3          0       0  
  #I can reference in to the result of applying table to get part of what I want  
  #First I get the table, this gets me a table by win/lose value  
  fooTable <- table(foo$Uid, foo$Win)  
  fooTable  

         FALSE TRUE  
  UidA     1    1  
  UidB     0    1  
  UidC     1    0  

  # I can get at the actual results via unname which gives me a matrix  
  fooTableAsMat <- unname(fooTable)  
  fooTableAsMat  
     [,1] [,2]  
[1,]    1    1  
[2,]    0    1  
[3,]    1    0  

  #but the UID vec is hidden in the table structure *somewhere* and   
  # I can't work out how to reference it out  

  #coercing the result to a dataFrame doesn't work

  as.data.frame(fooTable)  
    Var1  Var2 Freq  
  1 UidA FALSE    1  
  2 UidB FALSE    0  
  3 UidC FALSE    1  
  4 UidA  TRUE    1  
  5 UidB  TRUE    1  
  6 UidC  TRUE    0  

  #I have also tried 'aggregate' but have not made friends with it
  • 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-18T10:48:12+00:00Added an answer on June 18, 2026 at 10:48 am

    Does this help?

    Using plyr:

    > ddply(foo, .(Uid), summarise, NWin = sum(Win), NRunUp = sum(!Win))
    #    Uid NWin NRunUp
    # 1 UidA    1      1
    # 2 UidB    1      0
    # 3 UidC    0      1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Doing this: s = hello s[0] outputs the character code value 104 . What
Doing some work in javascript I have a multidimensional made up in this format
Doing the getting started of Sinatra. I get this error: ./sinatra.rb:5: undefined method `get'
Doing an ajax get request works as expected using the following code: $.ajax({ type:
Doing my first SL4 MVVM RIA based application and i ran into the following
Doing the below will reproduce my problem: New WPF Project Add ListView Name the
Doing my first tryouts with foreign keys in a mySQL database and are trying
Doing some jquery animation. I have certain divs set up with an attribute of
Doing some homework here (second assignment, still extremely green...). The object is to read
Doing a mysqli query and COUNTing the results, is there a preferred comparison operator

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.