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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:03:05+00:00 2026-05-22T23:03:05+00:00

I want a function f such that (outer(X, Y, f))[i, j] is a side-by-side

  • 0

I want a function f such that

(outer(X, Y, f))[i, j] is a side-by-side concatenation of the i-th element of X and the j-th element of Y, something like c(X[i], Y[j]), or having a similar structure.

Furthermore, I want this result to be such that the process can be repeated, and, in this way we get that

(outer(outer(X, Y, f), Z, f))[i, j, k] is a side-by-side concatenation of the i-th element of X, the j-th element of Y, and the k-th element of Z, i.e. something equal, or having a structure similar to that of, c(X[i], Y[j], Z[k]).

Ultimately I am aiming for defining a function like this:

foo <- function(a.list) {
  Reduce(function(x, y) outer(x, y, f), a.list)
}

such that, if

A <- foo(list(v_1, ..., v_p))

then dim(A) will be c(length(v_1), ..., length(v_p)), and

A[i_1, ..., i_p] == c(v_1[i_1], ..., v_p[i_p])

for all valid index sets (i_1, …, i_p).

For example:

> foo(list(LETTERS[1:2], c(3, 4, 5), letters[6:7]))
, , 1

               [,1]           [,2]           [,3]
[1,] c("A", 3, "f") c("A", 4, "f") c("A", 5, "f")
[2,] c("B", 3, "f") c("B", 4, "f") c("B", 5, "f")

, , 2

               [,1]           [,2]           [,3]
[1,] c("A", 3, "g") c("A", 4, "g") c("A", 5, "g")
[2,] c("B", 3, "g") c("B", 4, "g") c("B", 5, "g")

(NOTE: I don’t know if an array of vectors like the result shown in the example above is even valid/possible in R, but I am using expressions like c("A", 3, "f") to suggest ‘some vector-like object whose elements are “A”, 3, and “f”‘.)

What can I use for f to achieve this?

Thanks!

  • 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-05-22T23:03:06+00:00Added an answer on May 22, 2026 at 11:03 pm

    The function Vectorize() is your friend here: define f to be:

    f <- Vectorize( function(a,b) c(as.list(a), as.list(b)), SIMPLIFY = FALSE )
    

    Then you can do (with your definition of foo above):

    z <- foo(list(LETTERS[1:2], c(3, 4, 5), letters[6:7]))
    

    For example you can check that the entries match your example above:

    > z
    , , 1
    
         [,1]   [,2]   [,3]  
    [1,] List,3 List,3 List,3
    [2,] List,3 List,3 List,3
    
    , , 2
    
         [,1]   [,2]   [,3]  
    [1,] List,3 List,3 List,3
    [2,] List,3 List,3 List,3
    
    > z[2,2,2]
    [[1]]
    [[1]][[1]]
    [1] "B"
    
    [[1]][[2]]
    [1] 4
    
    [[1]][[3]]
    [1] "g"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ideally I want a function something like the following (this example doesn't compile): void
I'm trying to call a function that contains jQuery code. I want this function
I want to write a function such that when class clipartcategory clicked above of
I want to write a function myFunc such that: myFunc /function foo/ becomes :vimgrep
I want to create a function such that each time the function runs, the
I want to have a generic function for a few types such as long,
I want a function/code which will return the value that the user submitted for
I just want a function that can take 2 parameters: the URL to POST
I only want this function to run if .toolbar li does not have the
Say I want a function that takes two floats ( x and y ),

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.