0

I am not sure how to condense this question for a good title, so my apologies for the vagueness of the title. My problem is more complex (I think).

I am trying to write a code so that all I need to do is input my raw data, and R does all my statistical analysis for me with little effort from my part once I have written the code.

It will have to be done in stages, and at them moment I am just trying to create a function to create a standard curve for me.

My first obstacle is a for loop that I am using to prompt me to input my lines of data in order of replicates. I would like the code to return:

rep1 = c(1,2,3,4)
rep2 = c(1,2,3,4)
rep3 = c(1,2,3,4) (as an example)

For this I have used the following code which returns a non-numeric list of data that it prompted me to input:

for(x in c(1:3)){

assign(paste("rep", x, sep = ""),readline("Enter Dataset"))

}

To correct this, I tried the as.numeric() command to obtain numeric vectors, as follows:

for(x in c(1:3)){

as.numeric(unlist(strsplit(assign(paste("rep", x, sep = ""),
readline("Enter Dataset")), ",")))

}

However this code just returns the same response as the first code when I input my data.

Would anyone be able to offer an alternative method, or be able to get the second code to return numeric vectors as named above.

As a purely aesthetic addition, I would also like the code to request the data as follows:

Enter Dataset 1
Enter Dataset 2
Enter Dataset 3

depending on which iteration in the for loop is being requested.

This is a simplified version of my code, in reality I have many more replicates, and these vary with each experiment; I am able to code to take this into account, but it is not as neat as this simplified version.

Many thanks.

  • 1
    It's usually easier to work with named lists than with `assign` and `get`, see [How do I make a list of data frames](https://stackoverflow.com/a/24376207/903061) for some examples and discussion. – Gregor Thomas Aug 22 '17 at 22:25

1 Answers1

0

I'm not sure why you wrapped the entire line in an as.numeric--note that the readline() function is the one reading the input. Try the code below:

for(x in c(1:3)){
  assign(paste("rep", x, sep = ""),
         as.numeric(unlist(strsplit(readline(paste(c("Enter Dataset ", x, ": "), collapse = "")), ","))))
}
aku
  • 465
  • 4
  • 11
  • Did exactly as I wanted, thank you, especially for the fast response. –  Aug 23 '17 at 20:22