Problem creating a data.frame

Asked

Viewed 50 times

5

I want to export several results to excel and for that I need to first leave them in the ideal format, but I am facing problems because I want them to be stacked in a single column.
This is an example to show what I want to be done.

x=c(1,2,3)
x1=c("um","dois","tres")
d1=as.data.frame(x,x1)

z=1000
z1=c("média")
d2=as.data.frame(z,z1)

y=10
y1=c("taxa")
d3=as.data.frame(y,y1)

exportar=as.data.frame(list(d1,d2,d3))  

That’s the way out

inserir a descrição da imagem aqui

However, it omits the lines name "z" and "y" and triples some results. I want the output to be in the first column the row names of the variables and in the second column the values one below the other.

I want in the first column:
one
two
three
average
rate

and in the second:
1
2
3
1000
10

1 answer

4


As in your example you have the variables that will build the data.frame, in a very generic way you can do as follows:

data.frame(c(x,z,y), row.names = c(x1, z1, y1))

However, I think it’s smarter for you to indicate the indexed variables of each data.frame in this building:

data.frame(c(d1$x,d2$z,d3$y), row.names = c(row.names(d1),row.names(d2),row.names(d3)))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.