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 <- c(1:5)
Thanks for your help.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
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.
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.frameis a kind oflistwhere 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:
There are different ways to get back at the elements of
mylist, e.g.and likely more! Find a tutorial by searching for ‘R beginner tutorial’ and power through it. Have fun!