Arrays if==True;但内置函数并不';跑不动
职能:Arrays if==True;但内置函数并不';跑不动,arrays,r,string,function,Arrays,R,String,Function,职能: f chr[1:3000] "some string" "some string2" "FN:213123123123" ... names NULL (empty) numbers NULL (empty) f chr[1:3089] "asdasd" "asdasd" ... name "just last person's name" number "just last person's number" n
f chr[1:3000] "some string" "some string2" "FN:213123123123" ...
names NULL (empty)
numbers NULL (empty)
f chr[1:3089] "asdasd" "asdasd" ...
name "just last person's name"
number "just last person's number"
names "just last person's name in the list"
numbers "just last person's number in the list"
phone List of 2
因此名称和数字变量甚至不存在;名称列表显示一个空列表。
正如我所说,它返回了很多“你好,世界”。
所以我不明白问题出在哪里
亲切问候,
编辑:
职能:
f chr[1:3000] "some string" "some string2" "FN:213123123123" ...
names NULL (empty)
numbers NULL (empty)
f chr[1:3089] "asdasd" "asdasd" ...
name "just last person's name"
number "just last person's number"
names "just last person's name in the list"
numbers "just last person's number in the list"
phone List of 2
变量
名称
和数字
不存在于函数phonezz()之外
按上述建议添加返回(列表(姓名、号码)
。
然后将函数调用为
test\u list函数外部不存在变量names
和numbers
按上述建议添加返回(列表(姓名、号码)
。
然后将函数调用为test_list,这不会创建列表:
phonezz function ()
改用:
is.list(c())
[1] FALSE
还有一个问题是,您的for
-循环正在覆盖每个值。因此,如果您只得到一组值,您不应该感到惊讶。您需要在for
-循环内索引项目,然后在循环外,您需要另外应用return
操作。这不会创建list:
phonezz function ()
改用:
is.list(c())
[1] FALSE
还有一个问题是,您的for
-循环正在覆盖每个值。因此,如果您只得到一组值,您不应该感到惊讶。您需要在for
-循环内索引项目,然后在循环外,您需要另外应用return
操作。您需要添加return(列出(姓名、数字))
到函数末尾,你可以使用同样的事情发生。我改变了,还有一个逻辑错误。如果你从1
循环到length(f)
那么在循环的最后一次迭代中,当I=length(f)时,f[I+1]
是什么
?另外,我会为lop输入名称。你可以在其中输入打印语句来证明这一点。你需要在函数末尾添加return(list(name,numbers))
,你可以使用同样的事情发生。我更改了,还有一个逻辑错误。如果你从1
循环到length(f)
那么在循环的最后一次迭代中,当i=length(f)时,什么是f[i+1]
?另外,我会把lop的名字放进去。你可以在里面放一个打印语句来证明。我更新了原来的帖子。似乎新的人名/号码不能附加到人名/号码列表中。只是错了。无法理解for
函数的范围,以及如何初始化列表。我'我更新了原始帖子。新的人名/号码似乎无法添加到姓名/号码列表中。这是错误的。无法理解
函数的作用域,以及如何初始化列表。
my.names <- list() #don't use `names` ... it's the name of a function
numbers <- list()
substring("string", 4)
[1] "ing" # so it returns the entire "tail" of the the input character value