This is a sample (normally it is 15 x 17) from my dataset entrepreneur
imported from Excel with read_excel
:
structure(list(Factors = c("Competition", "Cultural Support", "Financing", "High Growth", "Human Capital"), `Baden-Württemberg` = c("0.71", "0.66", "0.81", "0.62", "0.46"), Bayern =c("0.67", "0.66", "0.83", "0.77", "0.49"), Berlin = c("1.00", "0.56", "0.90", "0.82", "0.79"), Brandenburg = c("1.00", "0.55", "0.64", "1.00", "0.77")), row.names = c(NA, -5L), class = c("tbl_df", "tbl", "data.frame"))
or in this format:
EntrepreneurIndex
# A tibble: 5 x 5
Factors `Baden-Württemberg` Bayern Berlin Brandenburg
<chr> <chr> <chr> <chr> <chr>
1 Competition 0.71 0.67 1.00 1.00
2 Cultural Support 0.66 0.66 0.56 0.55
3 Financing 0.81 0.83 0.90 0.64
4 High Growth 0.62 0.77 0.82 1.00
5 Human Capital 0.46 0.49 0.79 0.77
The first column as you can see is consisting of my factor variables. I would like to have the first column be transferred to rownames. I have used codes like
rownames(entrepreneur) <- entrepreneur[,1]
, which led to the error message error in `.rowNamesDF<-`(x, value = value) : non-valid 'row.names' length Zusätzlich: Warnmeldung: Setting row names on a tibble is deprecated.
I'm unfortunately new to the concept of tibbles.
I have tried transforming the data into a data frame as another post https://stackoverflow.com/a/50904626 has adviced with as.data.frame(entrepreneur)
, but this only lead to the same error message as before.
Going to https://tibble.tidyverse.org/reference/rownames.html adviced me to use
column_to_rownames(entrepreneur, var = "Factors")
This didn't cause an error, but it didn't transform the first column to rownames.
After reading the advice and other posts, I'm now not sure whether you can or cannot transfer the first column of a tibble into a row names column. Preferably I would have the first column a rowname for further analysis (regression, etc.) if that's possible.
First, you can see the difference
> str(entrepreneur[, 1])
tibble [5 x 1] (S3: tbl_df/tbl/data.frame)
$ Factors: chr [1:5] "Competition" "Cultural Support" "Financing" "High Growth" ...
> str(entrepreneur[[1]])
chr [1:5] "Competition" "Cultural Support" "Financing" "High Growth" ...
Try the code below (using entrepreneur[[1]]
rather than entrepreneur[,1]
)
> `rownames<-`(as.data.frame(entrepreneur[-1]), entrepreneur[[1]])
Baden-Wⁿrttemberg Bayern Berlin Brandenburg
Competition 0.71 0.67 1.00 1.00
Cultural Support 0.66 0.66 0.56 0.55
Financing 0.81 0.83 0.90 0.64
High Growth 0.62 0.77 0.82 1.00
Human Capital 0.46 0.49 0.79 0.77