I'm given a .csv data set and I want to establish a function for the data using a for loop. The data set has 5 columns, data consisting of either factors or numerics. If the data is a factor, nothing should be done, just print out the name of the column and it's class. If the data is numeric, then print out the name, class, as well as two functions (that I had already created beforehand).
I'm a bit lost on how to go about organizing the syntax for the function/for loop.
p.data <- read.csv("file.csv")
function(
x){
for.loop.variable <- for(index in data.csv){
if (class(x)) == "factor"
{cat("Name of Column is:", names(x*), "\n",
"Class of Column is :" , (class(x)))
} else {
cat("Name of Column is:", names(x*), "\n",
"Class of Column is :" , (class(x)),"\n",
"Function 1 is :", function.1(x), "\n",
"Function 2 is :", function.2(x), "\n")
}
}
}
return (for.loop.variable)
I think that's the right set up but I have 3 questions that I can't seem to figure out:
1- How does the for loop iteration come into play? I hadn't referenced it in the conditionals at all and I'm not sure how to go about doing so?
2*- How do I go about calling/printing the column name? I don't think it's names(x) but I'm not too sure what it would be other than that.
3- Is the return () correct? Should it return the entire for loop (once I figure out how to tie it into the actual problem) from the variable?
Please let me know where to fix errors so I can properly learn this, please.
Here's an image of the example code so it's a bit easier to read as far as brackets/syntax goes:
