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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:21:46+00:00 2026-06-04T01:21:46+00:00

In a typical spreadsheet I am able to create a formula that references a

  • 0

In a typical spreadsheet I am able to create a formula that references a cell on any row.

So let us say I have the following data:

a=1:10
b=11:20
c=data.frame(a,b)

Which would yield this:

    a  b
1   1 11
2   2 12
3   3 13
4   4 14
5   5 15
6   6 16
7   7 17
8   8 18
9   9 19
10 10 20

So in a spreadsheet I can place in what would be cell c2 the absolute formula c$b2*c$a1 and get the number 12. Or maybe even something more complex like ifelse(c$a>5,c$b*c$a[-1]*2,c$b*c$a[-1] using relative references.

    a  b   c
1   1 11  NA
2   2 12  12
3   3 13  26
4   4 14  42
5   5 15  60
6   6 16  80
7   7 17 204
8   8 18 252
9   9 19 304
10 10 20 360

I know R is not a spreadsheet, but is there a package or function that would allow me to treat data frames in such a manner or is there something fundamentally wrong with that kind of functionality? I keep having these issues with functions that require the spanning of more than one record or row. Almost all the stuff I work with is a time-series if that helps at all. Is there a document anywhere that explains such functions? Maybe there is a ?topic I missed somewhere.

  • 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-04T01:21:48+00:00Added an answer on June 4, 2026 at 1:21 am

    You were close, you need to complete the offset by excluding the first and last values, then wrap all that in ifelse:

    a = 1:10
    b = 11:20
    d = data.frame(a,b)
    d$c = ifelse(d$a > 5, c(NA, d$b[-1] * d$a[-nrow(d)]) * 2, c(NA, d$b[-1] * d$a[-nrow(d)]))
    

    (I choose d as a variable name since c is a very commonly used function.)

    For a tidier answer keep the main calculation out of the ifelse and use it only for the multiplier:

     d$c = ifelse(d$a > 5, 2, 1) * c(NA, d$b[-1] * d$a[-nrow(d)])
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a pretty typical bookmarklet code that's working perfectly for me in all
I have a situation where I currently have a huge spreadsheet that is used
Typical scenario: a class that a lot of people have worked on. I'd like
The typical Python threadpool will have a structure like this one: def run(self): while
My typical workflow is that I develop on localhost, but with Google Apps Marketplace
I have a typical User model (username, password, name, etc). I want to allow
Consider a typical social networking website, which has more or less the following models:
My typical usage of uploadify [www.uploadify.com] follows the following pattern: // to initialize $(#divid).uploadify({
A typical forward iterator is expected to implement following methods: value_type& operator*(); value_type* operator->();
In a typical organization application i create, entities User , Projects , Company ,

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.