Hi vie,
I've inserted comments within your message below.
Gina Liao wrote:
Hi, I'm new to R language.
There is a problem I couldn't understand.
Hope you can answer my question.
when i type
for (i in 1:10){
+ print(sample(9,4,replace=T))
+}
The above produces 10 vectors, each containing four numbers between 1 and 9.
and it shows ten of four numbers
and how do I do to calculate the frequencies in each list?
table(sample(9,4))
I know there is a hint; list10<-vector(mode="list",length=4)
What you probably want to do is to make each vector an element of a
list. If you really want a list containing four vectors with ten
integers in each vector, you want:
mysamplelist<-vector("list",4)
for(i in 1:4) mysamplelist[[i]]<-sample(9,10,TRUE)
sapply(mysamplelist,table)
But I don't know how to use it.
How do I name each list?
names(mysamplelist)<-c("Allan","Bertrand","Cicero","Dracula")
Jim
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.