Reputation: 840
Consider a data frame with row names and column names:
> data <- data.frame(a=1:3,b=2:4,c=3:5,row.names=c("x","y","z"))
> data
a b c
x 1 2 3
y 2 3 4
z 3 4 5
I just want to display the row names and column names of data like:
a b c
x
y
z
I want a data.frame
as output.
Upvotes: 1
Views: 1443
Reputation: 59
If you want to see the column names in your dataset just use this
print(names(dataset_name))
For its structure,
str(dataset_name)
Upvotes: 0
Reputation: 887531
Perhaps you need
data[] <- ''
data
# a b c
#x
#y
#z
If we need only the names, then dimnames
is an option which return the row names and column names in a list
.
dimnames(data)
#[[1]]
#[1] "x" "y" "z"
#[[2]]
#[1] "a" "b" "c"
Or may be
m1 <- matrix("", ncol = ncol(data), nrow = nrow(data),
dimnames = list(rownames(data), colnames(data)) )
Upvotes: 4