[問題] which(with)的使用方式

看板R_Language作者 (降太)時間11年前 (2013/04/09 18:46), 編輯推噓2(2011)
留言13則, 3人參與, 最新討論串1/1
我想利用監測資料劃出箱鬚圖,資料母體為全年度所有測站的數據 遇挑選其中一站做其全年度的特定物種(O3)的盒鬚圖 利用程式碼 ids <- which(with(newdata04,station == "忠明")) plot(as.factor(format(newdata04$measuretime[ids],"%m")), newdata04$O3) 得錯誤訊息 錯誤在model.frame.default(formula = y ~ x) : variable lengths differ (found for 'x') 其為參照OPENAIR'MANULA的寫法,但是最後顯示變數不定 是因為測站數與觀測時數不同嗎? 如果我想要從所有站中特別挑出某個站,對時間與測時作圖該如何給條件? ------------atrr(newdata04)部分結果------------- head(attributes(newdata04),10) $names [1] "number" "station" "measuretime" "SO2" "CO" "O3" "PM10" "NOx" "NO" "NO2" [11] "THC" "NMHC" "WIND_SPEED" "WIND_DIREC" "SIGMA" "WD_GLOBAL" "AMP_TEMP" "DEW_POINT" "SHELT_TEMP" "PRESSURE" [21] "PH_RAIN" "RAIN_COND" "RAINFALL" "CH4" "RAIN_INT" "area" $row.names [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 [25] 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 [49] 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 [73] 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 [97] 97 98 99 100 101 102 103 104 .. . . 99745 99746 99747 99748 99749 99750 99751 99752 99753 99754 99755 99756 99757 99758 99759 99760 99761 99762 99763 99764 99765 99766 99767 99768 [99769] 99769 99770 99771 99772 99773 99774 99775 99776 99777 99778 99779 99780 99781 99782 99783 99784 99785 99786 99787 99788 99789 99790 99791 99792 [99793] 99793 99794 99795 99796 99797 99798 99799 99800 99801 99802 99803 99804 99805 99806 99807 99808 99809 99810 99811 99812 99813 99814 99815 99816 [99817] 99817 99818 99819 99820 99821 99822 99823 99824 99825 99826 99827 99828 99829 99830 99831 99832 99833 99834 99835 99836 99837 99838 99839 99840 [99841] 99841 99842 99843 99844 99845 99846 99847 99848 99849 99850 99851 99852 99853 99854 99855 99856 99857 99858 99859 99860 99861 99862 99863 99864 [99865] 99865 99866 99867 99868 99869 99870 99871 99872 99873 99874 99875 99876 99877 99878 99879 99880 99881 99882 99883 99884 99885 99886 99887 99888 [99889] 99889 99890 99891 99892 99893 99894 99895 99896 99897 99898 99899 99900 99901 99902 99903 99904 99905 99906 99907 99908 99909 99910 99911 99912 [99913] 99913 99914 99915 99916 99917 99918 99919 99920 99921 99922 99923 99924 99925 99926 99927 99928 99929 99930 99931 99932 99933 99934 99935 99936 [99937] 99937 99938 99939 99940 99941 99942 99943 99944 99945 99946 99947 99948 99949 99950 99951 99952 99953 99954 99955 99956 99957 99958 99959 99960 [99961] 99961 99962 99963 99964 99965 99966 99967 99968 99969 99970 99971 99972 99973 99974 99975 99976 99977 99978 99979 99980 99981 99982 99983 99984 [99985] 99985 99986 99987 99988 99989 99990 99991 99992 99993 99994 99995 99996 99997 99998 99999 [ reached getOption("max.print") -- omitted 532449 entries ] $class [1] "data.frame" [軟體熟悉度]: 入門(寫過其他程式,只是對語法不熟悉) -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.120.29.185 ※ 編輯: zmack0905 來自: 140.120.29.185 (04/09 18:47)

04/09 18:56, , 1F
可能要描述一下 newdata04 裡面是長什麼樣子
04/09 18:56, 1F

04/09 18:57, , 2F
把 attributes(newdata04) 貼上來
04/09 18:57, 2F

04/09 19:03, , 3F
等唷
04/09 19:03, 3F
※ 編輯: zmack0905 來自: 140.120.29.185 (04/09 19:18) ※ 編輯: zmack0905 來自: 140.120.29.185 (04/09 19:18)

04/10 11:55, , 4F
試試建立一個變數指示是否是
04/10 11:55, 4F

04/10 11:56, , 5F
指定的站
04/10 11:56, 5F

04/10 12:18, , 6F
ex: is_x = c(TRUE, TRUE, FALSE, ....)
04/10 12:18, 6F

04/10 13:52, , 7F
有點懂了
04/10 13:52, 7F

04/10 13:52, , 8F
有許多問題
04/10 13:52, 8F

04/10 13:52, , 9F
1. plto(x群,y群) , x和y的長度不同
04/10 13:52, 9F

04/10 14:00, , 10F
你的x是忠明的 y 是全部的
04/10 14:00, 10F

04/10 14:01, , 11F
2. 你把 x 宣告為 factor
04/10 14:01, 11F

04/10 14:01, , 12F
這也塊怪的
04/10 14:01, 12F

04/10 14:01, , 13F
3. ids 改寫成 ; ids <- newdata04[,"station"] == "忠明"
04/10 14:01, 13F
文章代碼(AID): #1HO_6Y_R (R_Language)
文章代碼(AID): #1HO_6Y_R (R_Language)