【发布时间】:2019-04-13 18:47:15
【问题描述】:
我正在尝试在 R 中使用 for 循环来获取数据帧中的行数。
year1<-c("2001","2002","2003")
countries1<-c("Canada","USA","Mexico")
color1<-c("black","red","blue")
year2<-c("2010","2011","2012")
countries2<-c("France","Germany","Japan")
color2<-c("white","yellow","green")
df1<-data.frame(year1,countries1,color1)
df2<-data.frame(year2,countries2,color2)
for (i in c(df1,df2))
{
nb<-nrow(i)
print(nb)
}
我希望得到 3 和 3(因为每个数据帧有 3 行),但我得到 6“NULL”。你能帮帮我吗?
【问题讨论】:
标签: r loops dataframe for-loop