设置条件以解析data.frame时遇到问题

问题描述 投票:-1回答:1

seems like we have some extra artifacts that appear as the dataset changes firms. write a piece of code that checks to see where the tickers change, and delete all artifacts from those points

for (y in 1:nrow(longitudinal)){
 if (longitudinal[y,2] != longitudinal[y-1,2])
 {longitudinal[y,] = NA }}

嘿伙计们,我试图根据第2列中名称值的变化从数据集中的列中删除值。不幸的是我收到了错误

Ops.data.frame中的错误(纵向[y,2],纵向[y - 1,2]):'!='仅针对大小相等的数据帧定义

我想不出一种不同的方法来比较名称列中的元素,以便设置NA的条件对应于名称中的更改。非常感谢任何帮助思考这一点。

r for-loop condition
1个回答
0
投票

for循环必须从1行开始,即

y in 2:nrow(longitudinal)

因为条件会有第二个元素从第0行开始。

© www.soinside.com 2019 - 2024. All rights reserved.