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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:11:45+00:00 2026-06-05T02:11:45+00:00

Possible Duplicate: In R, what is the difference between the [] and [[]] notations

  • 0

Possible Duplicate:
In R, what is the difference between the [] and [[]] notations for accessing the elements of a list?

I’m confused with the difference of [1], [1,], [,1], [[1]] for dataframe type.

As I know, [1,] will fetch the first row of a matrix, [,1] will fetch the first column. [[1]] will fetch the first element of a list.

But I checked the document of data.frame, which says

A data frame is a list of variables of the same number of rows with
unique row names

Then I typed in some code to test the usage.

>L3 <- LETTERS[1:3]
>(d <- data.frame(cbind(x=1, y=1:10), fac=sample(L3, 10, replace=TRUE)))
  x  y fac
1  1  1   C
2  1  2   B
3  1  3   C
4  1  4   C
5  1  5   A
6  1  6   B
7  1  7   C
8  1  8   A
9  1  9   A
10 1 10   A
> d[1]
   x
1  1
2  1
3  1
4  1
5  1
6  1
7  1
8  1
9  1
10 1
>d[1,]
  x y fac
1 1 1   C
>d[,1]
 [1] 1 1 1 1 1 1 1 1 1 1
>d[[1]]
 [1] 1 1 1 1 1 1 1 1 1 1

What confused me is: [1,] and [,1] is only used in matrix. [[1]] is only used in list, and [1] is used in vector, but why all of them are available in dataframe?

Could anybody explain the difference of these usage?

  • 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-05T02:11:47+00:00Added an answer on June 5, 2026 at 2:11 am

    In R, operators are not used for one data type only. Operators can be overloaded for whatever data type you like (e.g. also S3/S4 classes).

    In fact, that’s the case for data.frames.

    • as data.frames are lists, the [i] and [[i]] (and $) show list-like behaviour.

    • row, colum indices do have an intuitive meaning for tables, and data.frames look like tables. Probably that is the reason why methods for data.frame [i, j] were defined.

    You can even look at the definitions, they are coded in the S3 system (so methodname.class):

    > `[.data.frame`
    

    and

    > `[[.data.frame`
    

    (the backticks quote the function name, otherwise R would try to use the operator and end up with a syntax error)

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

Sidebar

Related Questions

Possible Duplicate: Days difference between two dates I need to know how many days
Possible Duplicate: Difference between Activity Context and Application Context I want to know the
Possible Duplicate: Difference between -%> and %> in rails I need to know what
Possible Duplicate: Difference between ref and out parameters in .NET I know that ref
Possible Duplicate: difference between accessing a property via “propertyname” versus “self.propertyname” in objective-c? In
Possible Duplicate: Difference Between Equals and == in which cases equals() works exactly like
Possible Duplicate: difference between abstraction and encapsulation? What is the difference between abstraction and
Possible Duplicate: Difference between Visibility.Collapsed and Visibility.Hidden i am working on localization .and i
Possible Duplicate: Difference between pointer variable and reference variable in C++ When should I
Possible Duplicate: Difference between pointer variable and reference variable in C++ I am reading

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.