tpemartin / 109-1-inclass-practice

https://tpemartin.github.io/109-1-inclass-practice/flipCard.html
1 stars 90 forks source link

  用c( )堆疊記錄全班身高的問題 #27

Open tpemartin opened 4 years ago

tpemartin commented 4 years ago

老師請問一下 我想要練習這個收集資料的方法 image.png 可是執行後的結果 似乎只會儲存一個值呢 image.png image.png 這些是這段程式碼執行2次的結果


This is a good question. Among those three lines, one line has to be isolated. You only run two lines each time. Sorry that I can n't type those two lines since you post a pic and I can not copy paste from a pic.


entire = c() #收集資料的方法
height = sample(165:200, 1)
entire = c(entire , height)
老師這樣能copy了嗎? 轉成code的輸出了 ***
entire = c() #收集資料的方法
height = sample(165:200, 1)
entire = c(entire , height)

When you run it twice, it is like running

entire = c() #收集資料的方法
height = sample(165:200, 1)
entire = c(entire , height)
entire = c() #收集資料的方法
height = sample(165:200, 1)
entire = c(entire , height)

Now you pick up twice-running case, and run commands inside it ONE-BY-ONE. Each time you watch the change of entire in your Global environment. Can you find which command line remove the storage of your new height data?

That particular line is the one the makes your data storage project failed-- since it removes your past storage and let you start with a new storage again. You only need to remove ONE line in the twice-running case. And your code will work. *** 是第二次執行的第一行嗎? ***

是第二次執行的第一行嗎?

YES. Perfect.

*** entire = c()又再次清空了所儲存的值 *** That's right.
entire <- c()
is an initiator which functions as giving us a new empty bucket for data collection. We only need initiator to execute ONCE and AT THE BEGINNING. ***
entire = c()
height = sample(165:200, 1)
entire = c(entire , height)
所以應該像這樣分2行去執行嗎? 感謝老師! image.png ***

Our story line is:

Putting those sentences into computer codes:

entire <- c()

所以應該像這樣分2行去執行嗎?

Yes you're right.

*** OK 謝謝老師 *** The essence of computer programming is: Know how to layout your strategy in sentences and know how to translate them LINE-BY-LINE for computer to understand. You are welcome. I am glad someone notice this subtlety, which I believe most students did not notice. Good job.