Ajay Narottam Shah
2005-Aug-16 06:18 UTC
[R] Extracting some rows from a data frame - lapses into a vector
I have a data frame with one column "x":> str(data)`data.frame': 20 obs. of 1 variable: $ x: num 0.0495 0.0986 0.9662 0.7501 0.8621 ... Normally, I know that the notation dataframe[indexes,] gives you a new data frame which is the specified set of rows. But I find:> str(data[1:10,])num [1:10] 0.0495 0.0986 0.9662 0.7501 0.8621 ... Here, it looks like the operation data[1:10,] has converted it from type data frame into a numeric vector. Why does this happen, and what can I do about it? -- Ajay Shah Consultant ajayshah at mayin.org Department of Economic Affairs http://www.mayin.org/ajayshah Ministry of Finance, New Delhi
Dieter Menne
2005-Aug-16 06:26 UTC
[R] Extracting some rows from a data frame - lapses into a vector
Ajay Narottam Shah <ajayshah <at> mayin.org> writes:> > I have a data frame with one column "x": > > > str(data) > `data.frame': 20 obs. of 1 variable: > $ x: num 0.0495 0.0986 0.9662 0.7501 0.8621 .......> Here, it looks like the operation > data[1:10,] > has converted it from type data frame into a numeric vector. Why does > this happen, and what can I do about it?Check parameter "drop" in the documentation of "[" or Extract. The simplification to a vector is default behavior for historical reasons, but somewhat confusing. Dieter