让我们假设我们有下表mytable
:
Name id Factor Correct
___________________________________________ ________ _________ ____________
'Maria' '7324' 'x' 'Yes'
'Lina' '7827' 'x' 'Yes'
'Jack' '7831' '' 'No'
'Van' '7842a' 'x' 'No'
'Julia' '7842c' '' 'Yes'
我想选择mytable
Factor = 'x' AND Correct = 'Yes' 的所有行并将它们分配到一个新表中。对于每列的类(例如,'Name'
列),我们有:
class(mytable.Name) = cell
我试过这段代码:
newtable = mytable((mytable.Correct == 'Yes') & (mytable.Factor == 'x'))
并得到错误:
Undefined operator '==' for input arguments of type 'cell'
我尝试了第二种方法:
newtable = mytable((cell2mat(mytable.Correct) == 'Yes') & (cell2mat(mytable.Factor) == 'x'))
这一次得到了错误:
Error using cat
Dimensions of matrices being concatenated are not consistent.
这是有道理的,因为与“否”相比,“是”的大小不同。我正在考虑用“Y”和“N”重新分配“正确”列。然而,这并不是我真正想要的。有什么建议吗?