I have a dataframe with 10 rows
df <- c(1:10)
How do I add another column to the dataframe which has only 5 rows?
df2 &l
I'll give some little pointers here. See Tyler's answer a few questions back for a couple links to materials for getting started: convert data.frame column format from character to factor
1) The objects you're making with c() are called vectors, and that is a particular kind of object in R- the most basic and useful kind.
2) A data.frame is a kind of list where all the elements of the list are stuck together as columns and must be of the same length. The columns can be different data types (classes)
3) lists are the most versatile kind of object in R- the elements of a list can be anything- any size, any class. This appears to be what you're asking for.
So for instance:
mylist <- list(vec1 = c(1:10), vec2 = c(1:5))
mylist
$vec1
[1] 1 2 3 4 5 6 7 8 9 10
$vec2
[1] 1 2 3 4 5
There are different ways to get back at the elements of mylist, e.g.
mylist$vec1
mylist[1]
mylist[[1]]
mylist["vec1"]
mylist[["vec1"]]
and likely more! Find a tutorial by searching for 'R beginner tutorial' and power through it. Have fun!