I have no clue how to use reprex. I just tried to render in my rstudio and i did. I have no idea how to bring it in to this topic. I am trying my best. so I copied my code and explained what I am trying to do below. I really don't know why the directions for reprex arent more clear for first time attempt. there is a screen shot of my data at bottom.
I am attempting to create a results column for 2 different events each event has 2 requirements. I apologize for insufficiencies. if you could also help me w reprex... I need detailed step by step unfortunately
""
jorge <- alfaro
jorge <- jorge[ , c("fielder_2" , "player_name" , "pitch_type" , "Called_Strike" , "Ball" , "In_zone" , "Out_zone" ,
"plate_x" ,"plate_z")]
sampleRows <- sample(1:nrow(jorge) , 20)
jorge <- jorge[sampleRows , ]
I am trying to get a column named "results" where a pitch that is both called_strike and Out_zone is labled stolenK and
a pitch that is both called a ball and in the zone is labeled LostK.
operations are possible only for numeric, logical or complex types
I am confused on the second error as the variables are numerics
I am confused overall. I have never tried to combine two things in one if else and have no reference
Also, I do not know how mutate decides between stolen or lost. And truthfully I don’t have a clue.
would you mind offering a solution where you explain the answers to your questions. I understand what you are saying. first, is the first part of the statement correct?
mutate(result = ifelse(c(Called_Strike == 1 & Out_zone == 1 | Ball == 1 & In_zone == 1)
is that satisfactory or does it need adjustment? and second, if you would a solution w explanation... or more guided questions at least?
Thanks
I tried the following and it only created 0s
jorge %>%
mutate(result = ifelse(c(Called_Strike == 1 & Out_zone == 1) ,
"stolenK" , 0) ,
result = ifelse(c(Ball == 1 & In_zone == 1) ,
"lostK" , 0)) -> jorge
It's always hepful to include reproducible example, called a reprex with a short data sample to help responses to understand question and clarify answers.
Great! I'm glad that helped you find your way. Don't worry! It's easy to get lost in new features. I've been using R for over 10 years and I've gotten better at figuring out new packages and functions on my own, but I still go round and round at times before my aha! moment.
Also, you're using this community exactly the right way. Ask for help, clarification, then apply it on your own and report back. And keep in mind that often the person who answers what seem like simple question learns something new trying to explain it!
thanks for encouragement. I use it for baseball. there is so much data in baseball and many new interesting metrics: new class of statistics called saber. R is practically made just for it. I am currently working backwards from a script I copied. I understand most. It has some GAM models. I am going to see if my way will match my way. my way is always too long and harder than it should be.
I have just been using for about 9 months. I know too much of some and not enough of some basics. I am hoping to take class or classes soon. I live in Ny. would you know of anything that is serious and could lead to a certification or some sort of value?
I recommend the HarvardX professional certificate in data science, a 9-module course from the basics through statistical applications and machine learning. Taught as an orientation course for graduate students on non-CS tracks who will still need to be doing data analysis. I took it last year.