0
I have a column with three types of information: numerical, percentage and character. I would like to create two new columns from this, one with only the information in character getting the other cells "NA" and another column with only the numerical information getting the character information and the other "NA" in this new column. Goal is to create two new columns from the Code column. One with the numbers and the other with the codes (factor).
dput(head(estudo, 10)) structure(list(Potreiro = structure(c(3L, 3L, 3L, 3L, 3L, 4L, 3L, 4L, 3L, 4L), .Label = c("1A", "6B", "7A", "7B"), class = "factor"), Code = structure(c(4L, 1L, 8L, 3L, 2L, 4L, 6L, 5L, 8L, 7L ), .Label = c("2", "3", "4", "5", "50%", "70%", "ac", "ad", "av", "cd", "de", "Dem"), class = "factor")), .Names = c("Potreiro", "Code"), row.names = c(NA, 10L), class = "data.frame")
Welcome to Stackoverflow Brasil! Unfortunately, this question cannot be reproduced by anyone trying to answer it. Please, take a look at this link and see how to ask a reproducible question in R. So, people who wish to help you will be able to do this in the best possible way.
– Marcus Nunes
Be clearer please give examples of how you have tried to resolve the issue and use the formatting tools to improve the readability of the question.
– Andrey
Each column of a dataframe has only a guy information. As you are saying, the figures were transformed into character and then, almost certainly, into
factor
. Please edit the question with the output ofdput(df)
for us to see how it is.– Rui Barradas
Exactly Rui Barradas, are all as factor but I need to use some as number so I want to create more columns each with a type of information (number, factor...). I tried ifelse(), but gave error: behaviour2$heigth <- ifelse(behaviour2$Code== ">1", Sep = """) Error in ifelse(behaviour2$Code == ">1", Sep = ""): unused argument (Sep = """) and also behaviour2$heigth <- ifelse(behaviour2$Code== ">1") Error in ifelse(behaviour2$Code == ">1") : argument "no" is Missing, with no default Thank you very much!!!
– Júlio Azambuja
read the link that @Marcusnunes recommended and put the result of
dput(head(behaviour2, 10))
. A lot of people want to help you, but they can’t guess your problem, your description wasn’t enough.– Marcos Banik
Goal is to create two new columns from the Code column. One with the numbers and the other with the codes (factor). dput(head(study, 10)) Structure(list(Potreiro = Structure(c(3L, 3L, 3L, 3L, 3L, 4L, 3L, 4L, 3L, 4L), label = c("1A", "6B", "7A", "7B"), class = "factor"), Code = Structure(c(4L, 1L, 8L, 3L, 2L, 4L, 6L, 5L, 8L, 7L&Xa; ), label = c("2", "3", "4", "5", "50%", "70%", "ac", "ad", "av", "cd", "de", "Dem"), class = "factor")), names = c("Potreiro", "Code"), Row.Names = c(NA, 10L), class = "data.frame") Thank you very much!!
– Júlio Azambuja