0

In R I try and make a loop/lapply function to run a list of characters through a function that processes and t.tests them. I am currently trying to run the function with a predefined variable, however I would like to have the function repeat down a list.

Data_F = ABC #this references a row in the Data1 Matrix. Data_Fs is the Columns.
Variable="item"
ttestFunc <-function(x){
#Make a matrix one tall to turn into a numeric vector
Data1[Data_F, Data_Fs]-> "ttesttest"
as.numeric-> "ttestvect"
t.test(ttestvect, ttestvect)

Basically, I would like to know how to loop through multiple variables to input into Data_F instead of the predefined ABC. I want to loop through a vector like

c("ABC", "ABB", "XYZ")
T fish
  • 25
  • 6
  • When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jun 21 '18 at 18:54

1 Answers1

0

Do you mean something like this? You can just loop through the length of the target vector and use each item as you encounter it:

> targets <- c("ABC", "ABB", "XYZ")
> for (i in 1:length(targets)) { write(paste0("value is: ",targets[i]), stdout()) }
value is: ABC
value is: ABB
value is: XYZ
mysteRious
  • 4,102
  • 2
  • 16
  • 36