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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T12:31:54+00:00 2026-06-11T12:31:54+00:00

Can someone explain why in the below example the column name for why appears

  • 0

Can someone explain why in the below example the column name for why appears to remain x even though it is clearly named why and can be called as such but not for the column zz?

df<-data.frame(x=1:5,y=1:5)
df$z<-"a"
df$zz<-df$x*df$y
df$why<-df[1]*df[2]

df

df["why"]
  • 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-11T12:31:55+00:00Added an answer on June 11, 2026 at 12:31 pm

    Because you’re actually storing a dataframe into why – not a vector.

    > str(df)
    'data.frame':   5 obs. of  4 variables:
     $ x  : int  1 2 3 4 5
     $ y  : int  1 2 3 4 5
     $ z  : chr  "a" "a" "a" "a" ...
     $ why:'data.frame':    5 obs. of  1 variable:
      ..$ x: int  1 4 9 16 25
    > str(df[1]*df[2])
    'data.frame':   5 obs. of  1 variable:
     $ x: int  1 4 9 16 25
    > str(df[,1] * df[,2])
     int [1:5] 1 4 9 16 25  
    > df$why2 <- df[,1]*df[,2]
    > df
      x y z  x why2
    1 1 1 a  1    1
    2 2 2 a  4    4
    3 3 3 a  9    9
    4 4 4 a 16   16
    5 5 5 a 25   25
    

    df[1] returns the first element of df as a sublist. A dataframe is a special type of list which is why you can use this type of indexing to grab columns. However only using the single bracket tells it to return a sublist containing the element of interest (instead of just the element of interest).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone explain the statement below to me with a working sample/example. thanks in
I keep finding some JavaScript that looks like the example below. Can someone explain
Can someone explain what is happening in the example below: glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glRotatef(45,0,0,1);
Can someone explain me the syntax below line 1? I am OK with js
Can someone please explain the purpose of double-negating the reverse var in the below
Can someone please explain below in detail, 1- What is the use of ActivityManager
Can someone please explain the below to me. First is how I call the
hi can someone explain why the coding below does not work but it work
Can someone explain this simple, yet deceiving, anomaly? There are two models, where B
Can someone explain me why this works: select val1, val2, count(case when table2.someID in

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.