1:5
for(i in 1:5) print(i)
ss <- seq(from=1, to=10, by=0.1)
for(s in ss) {
print(s)
}
df = data.frame(
age=c(21, 22, 23),
name=c('KEN', 'John', 'JIMI'),
stringsAsFactors = FALSE
);
#如果用in进行遍历data.frame,那么默认按列遍历
for(l in df) {
print(l);
print(l['age'])
print(l['name'])
print("---------------------")
}
for(i in 1:nrow(df)) {
l <- df[i, ]
print(l);
print(l['age'])
print(l['name'])
print("---------------------")
}
i = 0
while(i<5) {
i <- i+1;
print(1:i);
}
i = 0
while(i<5) {
i <- i+1
if(i==4) {
next;
}
print(1:i);
}
i = 0
while(TRUE) {
i <- i+1
if(i==4) {
next;
}
print(1:i);
if(i==10) {
break;
}
}
i = 0
repeat {
i <- i+1
if(i==4) {
next;
}
print(1:i);
if(i==10) {
break;
}
}