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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:36:32+00:00 2026-06-18T12:36:32+00:00

I really like using the frame syntax in R. However, if I try to

  • 0

I really like using the frame syntax in R. However, if I try to do this with apply, it gives me an error that the input is a vector, not a frame (which is correct). Is there a similar function to mapply which will let me keep using the frame syntax?

df = data.frame(x = 1:5, y = 1:5)

# This works, but is hard to read because you have to remember what's
# in column 1 
apply(df, 1, function(row) row[1])

# I'd rather do this, but it gives me an error
apply(df, 1, function(row) row$x)
  • 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-18T12:36:34+00:00Added an answer on June 18, 2026 at 12:36 pm

    Youcab’t use the $ on an atomic vector, But I guess you want use it for readability. But you can use [ subsetter.

    Here an example. Please provide a reproducible example next time. Question in R specially have no sense without data.

    set.seed(1234)
    gidd <- data.frame(region=sample(letters[1:6],100,rep=T),
                       wbregion=sample(letters[1:6],100,rep=T),
                       foodshare=rnorm(100,0,1),
                       consincPPP05 = runif(100,0,5),
                       stringsAsFactors=F)
    
      apply(gidd, ## I am applying it in all the grid here!
              1, 
            function(row) {
            similarRows = gidd[gidd$wbregion == row['region'] &
                             gidd$consincPPP05 > .8 * as.numeric(row['consincPPP05']),
                           ]
        return(mean(similarRows$foodshare))
      })
    

    Note that with apply I need to convert to a numeric.

    You can also use plyr or data.table for a clean syntax , for example:

      apply(df,1,function(row)row[1]*2)
    

    is equivalent to

      ddply(df, 1, summarise, z = x*2)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to fetch information from the database using objects. i really like this
Can anyone explain why using comments like this in css cause really weird effects
So I rewrote my paths to something like: URL/really/nice/paths/ using mod_rewrite rules like this:
I have a data frame like this one below and I really want to
I really like how I can easily share files on a network using the
I have been using TortoiseSVN for some time and I really like it. I
I just started using Pantheios and it feels really like a great library for
I have started using MVC 3 and I really like working with it. It's
I am using jQuery Mobile for an iPhone app. I don't really like the
I'm using streetview as an embed in one of my pages. I'd really like

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.