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

  • Home
  • SEARCH
  • 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 8206189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:35:02+00:00 2026-06-07T08:35:02+00:00

I’m trying to apply a function to all the 334 rows of data frame

  • 0

I’m trying to apply a function to all the 334 rows of data frame M, which contains time and position data and get one value for each row. Instead, I get a list of 334 values for each row. How can I simply get one value per row calculated from the values of the variables of that same row?

These are the head and the tail of data frame M:

d mo    y   lat  long
 5  6 2007    NA    NA
 6  6 2007    NA    NA
 7  6 2007    NA    NA
 8  6 2007 26.89 15.53
 9  6 2007 28.00 15.73
10  6 2007 22.41 14.93
...
26  4 2008 23.86 14.05
27  4 2008 24.12 14.34
28  4 2008 27.75 12.87
29  4 2008 27.28 10.91
30  4 2008 24.17 14.44
1  5 2008    NA    NA

My code:

f1 = function(x){
         options(latitude= M$lat, longitude= M$long); 
         as.lt(moon.rst(jday = jd(M$y,M$mo,M$d)))
}
M$rs <- apply(M, 1, f1)
  • 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-07T08:35:06+00:00Added an answer on June 7, 2026 at 8:35 am
    f1  <- function(d, mo, y, lat, long){
      options(latitude = lat, longitude = long)
      as.lt(moon.rst(jday = jd(y, mo, d)))
    }
    data$rs <- do.call(f1, data)
    Warning message:
    In if (year < 0) c = floor((365.25 * year) - 0.75) else c = floor(365.25 *  :
      the condition has length > 1 and only the first element will be used
    data
       d mo    y   lat  long     rs.rise  rs.transit      rs.set
    1  8  6 2007 26.89 15.53  0h 24m 30s  5h 42m  2s 11h 42m 13s
    2  9  6 2007 28.00 15.73  1h  4m 42s  6h 34m  5s 12h 46m 30s
    3 10  6 2007 22.41 14.93  1h 54m 38s  7h 31m  8s 13h 53m 59s
    

    There is a warning from the function jd() since we are passing vectors (in this case year) as an argument, but despite this I hope that is the result that you need.

    Edit: Another version without any warnings, using apply, but using indices and it seemed for me that do.call is faster.

    f1 <- function(M){
      options(latitude= M[4], longitude= M[5]); 
      as.lt(moon.rst(jday = jd(M[3],M[2],M[1])))
    }
    apply(data[,c('d','mo','y','lat','long')], 1, f1)
    [[1]]
                      rise     transit         set
    2005-06-08  6h  2m 30s 13h  8m  3s 20h 12m 51s
    
    [[2]]
                      rise     transit         set
    2005-06-09  6h 55m 34s 14h  1m 26s 21h  4m 44s
    
    [[3]]
                      rise     transit         set
    2005-06-10  8h  7m 41s 14h 57m  7s 21h 43m 36s
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want to construct a data frame in an Rcpp function, but when I
I am trying to understand how to use SyndicationItem to display feed which is
I have a text area in my form which accepts all possible characters from
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I would like to run a str_replace or preg_replace which looks for certain words

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.