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

1 Answer

+1 vote
by (354k points)
selected by
 
Best answer

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

+1 vote
1 answer
+5 votes
1 answer
+3 votes
1 answer
+2 votes
1 answer

...