先设置一个Data Frame
df = data.frame(age=c(21, 22, 23),name=c('KEN', 'John', 'JIMI'),stringsAsFactors = FALSE);
输出df如下
age name1 21 KEN2 22 John3 23 JIMI
通过for循环来输出
for(i in 1:nrow(df)){ l<-df[i,] print(l) print(l['age'])}
其中,nrow(df)计算出df中行的数量,然后i在df所有行中循环遍历。
转载于:https://www.cnblogs.com/xugege/p/7357172.html