我在Python中編寫算法時遇到了麻煩,這不會是個大問題,但是r的語法已經把我拋棄了。 我想設置z和num等於eachother的第一個索引並將其放入列表中。 一旦在列表中,我想打印一個負數的字母。 然後我想打印對應於j k l的數字。r嵌套循環
nums<-c(1.0, 3.0, -2, 8, -4, 4, 2, -3, 9, 1, 4, 2, 2, 1, 8, 2)
z<-c("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p")
lets<-c(j,k,l)
for (i in nums){
for(j in z) {
}}
list=((a,1),(b,3),(c,-2),(d,8),(e,-4),(f,4),(g,2),(h,-3),(i,9),(j,1),(k,4),(l,2),(m,2),(n,1),(o,8),(p,2))
negative=c,e,h,
letters=1,4,2
'z [nums <0]'和'nums [z%in%lets]'?你錯過了你信件的引號 – Cath
僅供參考你也可以做'setNames(nums,z)' – Sotos