how to access particular list of variables from the data frame in a column using r code

how to access particular list of variables from the data frame in a column using r code for example if there are 10 variables in a column how to access last three variables

x <- c(11,12,13,14,15,16,17,18,19,20)
x
x[8:10]

[1] 11 12 13 14 15 16 17 18 19 20
[1] 18 19 20

It is not really clear what you are doing here. I think it may be a terminology problem. A list in particular has a very specific meaning in R.

Are you asking about Nested data or just how to access the last three items in a column in a data.frame?

If the latter,


## CREATE DATA SET
dat1  <- data.frame(xx = sample(letters[1:26], 10), yy = sample(1:5, 10, replace = TRUE))

dat1$xx[8:10]

dat1$yy[8:10]

We can be fancier but this is the most basic way to do it.

Hi,
Will try with the given inputs ,but just to be more clear
I have a data set having 9 columns and have to access last 10 items from that column.

What do you mean by that column? Do you mean something like

dat1  <- data.frame(matrix(1:90, ncol = 9))
dat1[8:10, ]

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.