В Wed, 30 Nov 2022 13:40:50 +0100 Luigi Marongiu <marongiu.lu...@gmail.com> пишет:
> I am formatting everything to either "POS" and "NEG", > but values entered as number should get the value "NUM". > How do I change such values? Thanks for providing an example! One idea would be to use a regular expression to locate numbers. For example, grepl('[0-9]', df$val) will return a logical vector indexing the rows containing digits. Alternatively, grepl('^[0-9.]+$', df$val, perl = TRUE) will index all strings consisting solely of digits and decimal separators. Another idea would be to parse all of the strings as numbers and filter out those that didn't succeed. Use as.numeric() to perform the parsing, suppressWarnings() to silence the messages telling you that the parsing failed for some of the strings and is.na() to get the logical vector indexing those entries that failed to parse. -- Best regards, Ivan ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.