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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:10:48+00:00 2026-06-13T20:10:48+00:00

i have a data frame, which looks like this, but huge so I can’t

  • 0

i have a data frame, which looks like this, but huge so I can’t do anything manually:

   Bank  Country  KeyItem    Year    Value 
    A      AU     Income     2010     1000
    A      AU     Income     2011     1130
    A      AU     Income     2012     1160
    B      USA    Depth      2010     10000

What I want to do is create a function where I can select the Bank, the Keyitem and from which year onwards and it returns a dataframe with the values as percentage of the first value . Like this:

   Bank  Country  KeyItem    Year    Value
    A      AU     Income     2010     100
    A      AU     Income     2011     113
    A      AU     Income     2012     116

Thank you 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-13T20:10:49+00:00Added an answer on June 13, 2026 at 8:10 pm

    Try the following approach: (df is your data frame)

    Choose the criteria:

    bank <- "A"
    keyItem <- "Income"
    year <- 2011
    

    Create a subset:

    dat <- subset(df, Bank == bank & KeyItem == keyItem & Year >= year)
    

    Calculate percentages:

    dat$Value <- dat$Value / dat$Value[1] * 100
    

    As a function:

    myfun <- function(df, bank, keyItem, year) {
       dat <- df[df$Bank == bank & df$KeyItem == keyItem & df$Year >= year, ]
       "[[<-"(dat, "Value", value = dat$Value / dat$Value[1] * 100)
    }
    
    myfun(df, "A", "Income", 2011)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following question: I have data frame which looks like this. I
I have a large data frame (named z ) that looks like this: RPos
Take this dataset... test <- data.frame( t1=c(2,3,5,6,7,10,10), t2=c(3,4,6,7,8,11,12), id=1:7 ) ...which looks like this.
I have a data.frame that looks like this: ID Date.A Date.B Variable A 01/01/2012
For a data frame populated from a SQL query which looks like this: Company
I have a data set that looks like this: ByYear <- data.frame( V1 =
I have a data frame like this: Server Date Server Space 1 2010-01-30 server1
I have a dataframe that looks like this: <class 'pandas.core.frame.DataFrame'> DatetimeIndex: 2016910 entries, 2009-01-02
I have a data.frame (which I melted using the melt function), from which I
Let's assume that we have a data frame x which contains the columns job

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.