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

The Archive Base Latest Questions

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

I have a data set with the following row-naming scheme: a.X.V where: a is

  • 0

I have a data set with the following row-naming scheme:

a.X.V
where:
a is a fixed-length core ID
X is a variable-length string that subsets a, which means I should keep X
V is a variable-length ID which specifies the individual elements of a.X to be averaged
. is one of {-,_}

What I am trying to do is take column averages of all the a.X's. A sample:

sampleList <- list("a.12.1"=c(1,2,3,4,5), "b.1.23"=c(3,4,1,4,5), "a.12.21"=c(5,7,2,8,9), "b.1.555"=c(6,8,9,0,6))
sampleList
$a.12.1
[1] 1 2 3 4 5

$b.1.23
[1] 3 4 1 4 5

$a.12.21
[1] 5 7 2 8 9

$b.1.555
[1] 6 8 9 0 6

Currently I am manually gsubbing out the .Vs to get a list of general :

sampleList <- t(as.data.frame(sampleList))
y <- rowNames(sampleList)
y <- gsub("(\\w\\.\\d+)\\.d+", "\\1", y)

Is there a faster way to do this?

This is one half of 2 issues I’ve encountered in a workflow. The other half was answered here.

  • 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:51:22+00:00Added an answer on June 13, 2026 at 7:51 am

    You can use a vector of patterns to find the locations of the columns you want to group. I included a pattern I knew wouldn’t match anything in order to show that the solution is robust to that situation.

    # A *named* vector of patterns you want to group by
    patterns <- c(a.12="^a.12",b.12="^b.12",c.12="^c.12")
    # Find the locations of those patterns in your list
    inds <- lapply(patterns, grep, x=names(sampleList))
    # Calculate the mean of each list element that matches the pattern
    out <- lapply(inds, function(i) 
      if(l <- length(i)) Reduce("+",sampleList[i])/l else NULL)
    # Set the names of the output
    names(out) <- names(patterns)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following data set that I am trying to plot with ggplot2,
I have the swiss data set provided by R, which has the following form:
I have a data set that looks like the following. EMPLID PHONE_TYPE PHONE ------
I have this data set made using write.zoo for which I used the following
I have the following data set structure: date time_in_hours price Sep 03 08 9.76
I have the following set of data: ID | CREATED | USER -------------------------- 1
I have the following data structures class Car { int CarID; string CarModel; string
I have a domain data model which returns a class such as the following:
I have the following data set with the 3rd field consists of 0's and
I have a data set that looks like the below (the input). IR# CR#

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.