I have two functions in R that convert a radian and an angle into Cartesian coordinates as follows:
x_cart<-function(theta,r){
return(r * cos (theta))
}
y_cart<-function(theta,r){
return(r * sin (theta))
}
Then I want to apply this function to create two new columns in my data frame as x and y from the columns angle and radius. When I use lapply, I get an error of argument r is missing with no default.
df$x<-apply(df[,c("angle_adj","hit_distance")],1, x_cart())
Test data
angle<-c(10,15,20)
radius<-c(15,35,10)
df<-data.frame(angle,radius)