问题的细节在这里列在此link的R - 需要澄清什么的代码
发生我不可能不明白什么在下面的代码行发生的事情:
Elite=rep("No",nrow(college))
Elite[college$Top10perc >50]=" Yes"
Elite=as.factor(Elite)
college=data.frame(college ,Elite)
我明白第二行和第三行,但其余的似乎很神秘。我真的很感谢在这个问题上的任何帮助。
感谢,
瑜珈
问题的细节在这里列在此link的R - 需要澄清什么的代码
发生我不可能不明白什么在下面的代码行发生的事情:
Elite=rep("No",nrow(college))
Elite[college$Top10perc >50]=" Yes"
Elite=as.factor(Elite)
college=data.frame(college ,Elite)
我明白第二行和第三行,但其余的似乎很神秘。我真的很感谢在这个问题上的任何帮助。
感谢,
瑜珈
不要包含的注释澄清你的问题吗?
#Create a vector of "No" of length equal to the number of rows in the dataframe college
Elite=rep("No",nrow(college))
#Subset the vector with the conditions of the column Top10perc > 50
#in the dataframe college and then set values to "YES"
Elite[college$Top10perc >50]=" Yes"
#Turn the Yes/No character strings into factors
Elite=as.factor(Elite)
#column bind the original dataframe with the newly created vector
#to update the original dataframe college.
college=data.frame(college ,Elite)
感谢您的回答。 我想澄清以下内容: 1.精英是一个完全独立的维度为[1xnrow(college)]的向量。矢量的所有值都是“否”。正确? – blackknight316
是的,它是一个独立的矢量。矢量中每个元素的值都是No – Dave2e
你不清楚哪个功能?你可以通过在R中输入'?rep'来打开任何这些函数的帮助页面(例如)。我假设你也可以单独运行每一行来查看正在发生的事情。这将有助于提出更具体的问题。 – MrFlick
我不清楚这些线路正在做什么。我没有尝试?在R的事。我会做到这一点。谢谢! – blackknight316