[R] creating a data.frame from scratch
Drake Gossi
dr@ke@go@@| @end|ng |rom gm@||@com
Sat Apr 20 01:39:39 CEST 2019
Hello everyone,
Is there any way to create a data.frame from scratch? other than, say, this?
> structure(list(Fruit = structure(c(1L, 2L, 5L, 4L, 3L), .Label =
c("apple",
"banana", "kiwi", "orange", "pear"), class = "factor"), Color =
structure(c(3L,
4L, 1L, 2L, 1L), .Label = c("green", "orange", "red", "yellow"
), class = "factor"), Shape = structure(c(3L, 1L, 2L, 3L, 3L), .Label =
c("oblong",
"pear", "round"), class = "factor"), Juice = c(1, 0, 0.5, 1,
0)), class = "data.frame", row.names = c("1", "2", "3", "4",
"5"))
which yields
Fruit Color Shape Juice
1 apple red round 1.0
2 banana yellow oblong 0.0
3 pear green pear 0.5
4 orange orange round 1.0
5 kiwi green round 0.0
I get *that* it works. I just don't know *how* it works, and whether or not
there is another, easier way...
For example,
> structure(list(Fruit = structure(c(1L, 2L, 5L, 4L, 3L), .Label =
c("apple", "banana", "kiwi", "orange", "pear") ...
What on earth are these numbers? c(1L, 2L, 5L, 4L, 3L)? and why are they
out of order?
And then why put the fruits out of order? c("apple",
"banana", "kiwi", "orange", "pear")? since that's not a descending order?
since, in the final data.frame, it goes apple, banana, *pear*, *orange*,
kiwi?
So many questions!
Drake
[[alternative HTML version deleted]]
More information about the R-help
mailing list