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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:42:39+00:00 2026-06-09T13:42:39+00:00

I like to generate a vector containing 0s and 1s from a comparison of

  • 0

I like to generate a vector containing 0s and 1s from a comparison of a vector with the elements of a list. I
have the following vector:

functions=c("abline", "as.numeric", "attach", "data.frame", "ddply", "mean")

This “functions” vector now should be comared to a list of vectors containing a subset of this vector. The list looks like this:

[[1]]
[1] "data.frame"

[[2]]
[1] "data.frame" "ddply"      "mean"      

[[3]]
[1] "data.frame" "abline"      "attach"      "mean"
... 

As a result I would like to produce a vector following the order and length of the “functions” vector containing a 1 for each element matching the “functions” vector and an 0 for not available. All of those i would like to put into a dataframe. For this three list elements this result would look something like the following:

    "abline" "as.numeric" "attach" "data.frame"  "ddply"  "mean"
1      0          0          0           1          0       0
2      0          0          0           1          1       1
3      1          0          1           1          0       1

Has anybody an idea how I could achieve this?

Best Sab.

  • 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-09T13:42:40+00:00Added an answer on June 9, 2026 at 1:42 pm

    Create the data

    functions=c("abline", "as.numeric", "attach", "data.frame", "ddply", "mean")
    
    mylist <- list(
      c("data.frame"),
      c("data.frame","ddply","mean"),
      c("data.frame","abline","attach","mean")
    )
    

    Then you could simply do:

    > solution <- lapply(mylist,function(i) as.numeric(functions %in% i))
    
    > mydf <- as.data.frame(do.call(rbind,solution))
    
    > names(mydf) <- functions
    
    > mydf
      abline as.numeric attach data.frame ddply mean
    1      0          0      0          1     0    0
    2      0          0      0          1     1    1
    3      1          0      1          1     0    1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a vector containing large number of elements. Now I want to write
I would like to generate a patch with all commits from a local branch.
Lets say for example I have the following 2 vectors: *B *A The vector
I would like to use the data.table package in R to dynamically generate aggregations,
I would like to generate text images like the following (source: http://www.zune.net/en-US ): The
I'm trying to generate a vector graphic from an area in a bitmap image,
How would I generate a vector like x1,x2,x3,x4,...,xn the problem is concatenate ','and a
Assume I have an array/vector of numbers like 1,3,7,9 then I need to guess
The homework task sounds something like this Generate a random vector of 4*n uniform
I have a data set that looks like this: 000 100 200 300 010

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.