+4 votes
in Programming Languages by (5.4k points)
What R function should I use to create a dataframe with a couple of columns and rows?

1 Answer

0 votes
by (33.7k points)
edited by

To create a data frame, R function data.frame() can be used. For column values, you can create vectors of the same size. The name of the column can be declared in the function itself.

Here is an example:

> xvals = c(10,20,30,40,50)
> yvals = c(100,200,300,400,500)
> df <- data.frame(x=xvals, y=yvals)
> df
   x   y
1 10 100
2 20 200
3 30 300
4 40 400
5 50 500

Related questions

...