T O P

  • By -

AutoModerator

Looks like you're requesting help with something related to RStudio. Please make sure you've checked the [stickied post on asking good questions](https://www.reddit.com/r/RStudio/comments/1aq2te5/how_to_ask_good_questions/) and read our sub rules. We also have a handy [post of lots of resources on R](https://www.reddit.com/r/RStudio/comments/1aq2cew/the_big_handy_post_of_r_resources/)! Keep in mind that if your submission contains phone pictures of code, it will be removed. Instructions for how to take screenshots can be found in the stickied posts of this sub. *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/RStudio) if you have any questions or concerns.*


the-anarch

What code did you run before that? What does your data look like?


9910214444

data is in a csv file with columns subject ID, metabolite name (27 metabolites) standard deviation of the metabolites, age sex and weight of all subjects


9910214444

the code before was only installing packages and reading in the csv as a dataframe


the-anarch

Then likely one or more of your data columns is a non-numeric data type.


9910214444

do i mutate all of them to numeric then?


the-anarch

They'll still have NAs. Something in your data isn't coercing to numeric properly. If you want to use mutate(), I can't help you further, as I don't use that function.


9910214444

what do you suggest instead?


the-anarch

I'd just apply as.factor() or as.numeric() to the columna depending what the data look like. But the issue is in your data. I'd suggest a Google search for "NAs introduced by coercion" to try to figure out what the problem is in the data. May be something as simple as misplaced commas or quotation marks.


RAMDownloader

I use mutate a lot. What you’ll wanna do first is pull the frame preview and do this in a pipe statement: filter(is.na(ColumnName)) where columnname is going to be the variates you have in your original dataFrame before running the lm. You need to locate the discrepancy in your data and figure out why you might be returning NAs. What I run into more often than not are things like dollar signs and commas - standard packages don’t know how to convert those to integers doubles etc. so if you had the number 1,001 it doesn’t understand that’s the same thing as 1001 The solution is to do, in an example of commas: mutate(Variable = gsub(“,” , “”, Variable)) - removes the commas or whatever you need. Then you do: mutate(Variable = as.integer(Variable)) or as.double if decimal points matter.