Hi y'all still new to r but I 've looked so I figure I might as well ask. Anyway I'm working with a pretty big dataset and I finally figured how to filter out what I want, but when I try to take the mean of the subsetted data all I get in return is NA for an answer. The code I'm using to filter the data is below.
test<-subset(data1,prodDate=="1999", select = prod)
I should mention the data1 object is stored under
data1<-na.omit(data)
If that means anything. Also if there's a package that makes this easier I'm all ears since it is already painful having to do this thanks.
@nirgrahamuk is pointing you in the right direction. This is what a similar piece would look like, using the built in mtcars dataset to find all the car models with 4 cyclinders
So I managed to figure it out and use the book, but when I try to take the mean of the filtered and selected data I get NA as well as the warning message that the argument is not logical or numeric. How do I take care of this. Below is how I wrote my code, it's crude but it works for me.
Thanks for the select code, much cleaner. I still get the NA response, I ran the summary function and it's saying the numbers in the list are characters
it is important to know ones data.
There is a great package you could install called skmir.
once you load the library(skimr)
you will be able to skim(data) and know whether your datatypes are numeric or character, and all sorts of things.
also you could share a sample of your data here. the first 5 records
dput(head(data,n=5))
copy and paste the structure that gets output here.
if you have a column that is numbers but stored incorrectly as character. the base method as.numeric(x) can be used. otherwise readr package has useful parse_number() function that is more powerful and can handle more subtle numeric representations than base.
seems a little odd to have an approach of converting to character before converting to numeric, but sometimes its a case of if it works it works I suppose