2
I make use of the functions apply
and, I need you to rownames
stay in the database after execution of these. Consider:
dataframe=structure(list(Composição100g = structure(c("Valor energético (KJ)",
"Proteína", "Glicídios", "Açúcar", "Amido", "Gorduras totais",
"Gorduras saturadas", "Colesterol", "Fibras", "Sódio", "Ferro",
"Ácido fólico", "Vitamina D", "Vitamina B12", "Vitamina C"), format.spss = "A22", display_width = 17L),
AllBran = structure(c(1150, 13, 46, 17, 29, 4.5, 0.9, 0,
28, 0.8, 8.8, 250, 3.1, 1, 0), format.spss = "F8.1"), Crunch = structure(c(1600,
6, 83, 39, 44, 2.5, 1, 0, 3, 0.7, 7.9, 333, 0, 0.8, 0), format.spss = "F8.1"),
CornFlakes = structure(c(1600, 7, 84, 7, 77, 0.8, 0.2, 0,
2.5, 0.9, 7.9, 167, 4.2, 0.8, 0), format.spss = "F8.1"),
ChocoKrispis = structure(c(1600, 6, 85, 35, 50, 2, 0.5, 0,
2, 0.6, 7.9, 333, 0, 0.8, 0), format.spss = "F8.1"), Muesli = structure(c(1150,
10, 58, 15, 43, 10, 2.5, 0, 9, 0.1, 5, 2, 3, 1, 0), format.spss = "F8.1"),
SpecialK = structure(c(1600, 16, 75, 17, 58, 1, 0.3, 0, 2.5,
0.8, 23.3, 333, 8.3, 1.7, 100), format.spss = "F8.1"), FrootLoop = structure(c(1550,
14, 74, 22, 52, 1, 0.3, 0, 3.5, 0.7, 21, 300, 7.5, 1.5, 90
), format.spss = "F8.1")), .Names = c("Composição100g",
"AllBran", "Crunch", "CornFlakes", "ChocoKrispis", "Muesli",
"SpecialK", "FrootLoop"), row.names = c(NA, -15L), class = "data.frame")
Where I executed:
#inserir uma variável comum como rownames
row.names(cereais)<-cereais$Composição100g
cereais[1]<-NULL
and, after:
cereais<-data.frame(cereais<-apply(cereais,2,as.numeric))
and rownames
is reset. I tried some functions found in ONLY, but when there is no error, a list is created (what I do not want).
What to do to preserve rownames
within the dataframe after using functions apply
?
I understood the concept you passed, @Rui Barradas. However, my goal is to keep
rownames
, that is, the column that names the rows of the dataframe. When I run my (and your) function, their names are replaced by numbers (1,2,3...).– neves
@Giovani Sorry, I read badly! I’ll see better...
– Rui Barradas
@Giovani Feito, look now.
– Rui Barradas
All right, @Rui Barradas. Grateful.
– neves