bamboohydraulics
2012-Mar-26 05:23 UTC
[R] reading header in txt file and making histogram
Dear all I am a BEGINNER and have R on my Mac. I saved my excel file as .txt file, I have just one column with first row as the column name. My file when read by R looks like this. After reading the table I try to make a histogram by hist(dbh), it says object dbh not found. What am I doing wrong? thanks dbh 1 11.53 2 16.05 3 7.36 4 16.05 5 8.66 6 12.74 7 22.93 8 7.55 9 5.10 10 21.34 11 0.32 12 9.71 13 0.00 14 15.92 15 11.85 16 14.43 17 4.59 18 14.43 19 7.99 20 2.61 21 23.69 22 6.05 23 9.87 24 4.90 25 3.18 26 3.82 27 0.00 28 12.10 29 5.22 30 6.37 31 6.50 32 10.83 33 3.63 34 2.93 35 3.60 36 5.89 37 3.63 38 2.55 39 2.96 40 3.69 41 5.57 42 0.00 43 7.07 44 5.48 45 9.55 46 3.44 47 0.00 48 0.00 49 3.69 50 2.48 51 3.38 52 2.64 53 12.10 54 3.34 55 0.00 56 4.52 57 6.59 58 9.65 59 9.01 60 12.93 61 0.00 62 4.24 63 9.75 64 4.39 65 2.90 66 6.85 67 9.08 68 5.54 69 6.02 70 7.64 71 6.85 72 0.00 73 3.12 74 6.75 75 4.24 76 2.32 77 2.58 78 2.55 79 8.60 80 0.00 81 0.32 82 2.23 83 3.98 84 6.05 85 7.64 86 3.03 87 0.00 88 9.27 89 0.00 90 0.00 91 3.92 92 0.00 93 20.54 94 8.41 95 0.00 96 2.10 97 0.00 98 0.00 99 13.79 100 5.22 101 9.43 102 6.31 103 4.11 104 0.00 105 0.00 106 6.15 107 3.41 108 14.01 109 15.67 110 17.20 111 20.00 112 11.43 113 10.35 114 10.29 115 13.18 116 10.61 117 0.00 118 0.32 119 0.00 120 7.01 121 1.97 122 4.52 123 19.14 124 3.50 125 2.99 126 3.18 127 1.82 128 3.18 129 6.02 130 4.04 131 2.61 132 2.48 133 2.71 134 2.68 135 1.82 136 2.52 137 6.72 138 2.61 139 2.74 140 3.15 141 3.25 142 3.22 143 3.44 144 4.01 145 4.97 146 6.15 147 9.62 148 2.87 149 5.83 150 17.90 151 3.18 152 3.54 153 2.99 154 4.62 155 6.85 156 0.00 157 5.83 158 4.49 159 2.74 160 6.82 161 6.82 162 4.94 163 5.83 164 6.02 165 0.96 -- View this message in context: http://r.789695.n4.nabble.com/reading-header-in-txt-file-and-making-histogram-tp4504813p4504813.html Sent from the R help mailing list archive at Nabble.com.
dbh is the column name. What is the name of your data? Lets assume your data is called "YOUR_DATA" then try: with(YOUR_DATA, hist(dbh)) OR hist(YOUR_DATA$dbh) OR hist(YOUR_DATA[, "dbh"]) etc... bamboohydraulics wrote> > Dear all > > I am a BEGINNER and have R on my Mac. I saved my excel file as .txt file, > I have just one column with first row as the column name. My file when > read by R looks like this. After reading the table I try to make a > histogram by > hist(dbh), it says object dbh not found. What am I doing wrong? thanks > dbh > 1 11.53 > 2 16.05 > 3 7.36 > 4 16.05 > 5 8.66 > 6 12.74 > 7 22.93 > 8 7.55 > 9 5.10 > 10 21.34 > 11 0.32 > 12 9.71 > 13 0.00 > 14 15.92 > 15 11.85 > 16 14.43 > 17 4.59 > 18 14.43 > 19 7.99 > 20 2.61 > 21 23.69 > 22 6.05 > 23 9.87 > 24 4.90 > 25 3.18 > 26 3.82 > 27 0.00 > 28 12.10 > 29 5.22 > 30 6.37 > 31 6.50 > 32 10.83 > 33 3.63 > 34 2.93 > 35 3.60 > 36 5.89 > 37 3.63 > 38 2.55 > 39 2.96 > 40 3.69 > 41 5.57 > 42 0.00 > 43 7.07 > 44 5.48 > 45 9.55 > 46 3.44 > 47 0.00 > 48 0.00 > 49 3.69 > 50 2.48 > 51 3.38 > 52 2.64 > 53 12.10 > 54 3.34 > 55 0.00 > 56 4.52 > 57 6.59 > 58 9.65 > 59 9.01 > 60 12.93 > 61 0.00 > 62 4.24 > 63 9.75 > 64 4.39 > 65 2.90 > 66 6.85 > 67 9.08 > 68 5.54 > 69 6.02 > 70 7.64 > 71 6.85 > 72 0.00 > 73 3.12 > 74 6.75 > 75 4.24 > 76 2.32 > 77 2.58 > 78 2.55 > 79 8.60 > 80 0.00 > 81 0.32 > 82 2.23 > 83 3.98 > 84 6.05 > 85 7.64 > 86 3.03 > 87 0.00 > 88 9.27 > 89 0.00 > 90 0.00 > 91 3.92 > 92 0.00 > 93 20.54 > 94 8.41 > 95 0.00 > 96 2.10 > 97 0.00 > 98 0.00 > 99 13.79 > 100 5.22 > 101 9.43 > 102 6.31 > 103 4.11 > 104 0.00 > 105 0.00 > 106 6.15 > 107 3.41 > 108 14.01 > 109 15.67 > 110 17.20 > 111 20.00 > 112 11.43 > 113 10.35 > 114 10.29 > 115 13.18 > 116 10.61 > 117 0.00 > 118 0.32 > 119 0.00 > 120 7.01 > 121 1.97 > 122 4.52 > 123 19.14 > 124 3.50 > 125 2.99 > 126 3.18 > 127 1.82 > 128 3.18 > 129 6.02 > 130 4.04 > 131 2.61 > 132 2.48 > 133 2.71 > 134 2.68 > 135 1.82 > 136 2.52 > 137 6.72 > 138 2.61 > 139 2.74 > 140 3.15 > 141 3.25 > 142 3.22 > 143 3.44 > 144 4.01 > 145 4.97 > 146 6.15 > 147 9.62 > 148 2.87 > 149 5.83 > 150 17.90 > 151 3.18 > 152 3.54 > 153 2.99 > 154 4.62 > 155 6.85 > 156 0.00 > 157 5.83 > 158 4.49 > 159 2.74 > 160 6.82 > 161 6.82 > 162 4.94 > 163 5.83 > 164 6.02 > 165 0.96 >-- View this message in context: http://r.789695.n4.nabble.com/reading-header-in-txt-file-and-making-histogram-tp4504813p4504848.html Sent from the R help mailing list archive at Nabble.com.
Please provide your code as is requested in the posting guidelines. At a guess, you have read in your data into a data.frame called dhb with a variable called dhb. Try hist(dhb$dhb) and see what happens. To see a bit more of what you've got try str(dhb) to see what the sdtructure of the data is. John Kane Kingston ON Canada> -----Original Message----- > From: bamboohydraulics at gmail.com > Sent: Sun, 25 Mar 2012 22:23:18 -0700 (PDT) > To: r-help at r-project.org > Subject: [R] reading header in txt file and making histogram > > Dear all > > I am a BEGINNER and have R on my Mac. I saved my excel file as .txt file, > I > have just one column with first row as the column name. My file when read > by > R looks like this. After reading the table I try to make a histogram by > hist(dbh), it says object dbh not found. What am I doing wrong? thanks > dbh > 1 11.53 > 2 16.05 > 3 7.36 > 4 16.05 > 5 8.66 > 6 12.74 > 7 22.93 > 8 7.55 > 9 5.10 > 10 21.34 > 11 0.32 > 12 9.71 > 13 0.00 > 14 15.92 > 15 11.85 > 16 14.43 > 17 4.59 > 18 14.43 > 19 7.99 > 20 2.61 > 21 23.69 > 22 6.05 > 23 9.87 > 24 4.90 > 25 3.18 > 26 3.82 > 27 0.00 > 28 12.10 > 29 5.22 > 30 6.37 > 31 6.50 > 32 10.83 > 33 3.63 > 34 2.93 > 35 3.60 > 36 5.89 > 37 3.63 > 38 2.55 > 39 2.96 > 40 3.69 > 41 5.57 > 42 0.00 > 43 7.07 > 44 5.48 > 45 9.55 > 46 3.44 > 47 0.00 > 48 0.00 > 49 3.69 > 50 2.48 > 51 3.38 > 52 2.64 > 53 12.10 > 54 3.34 > 55 0.00 > 56 4.52 > 57 6.59 > 58 9.65 > 59 9.01 > 60 12.93 > 61 0.00 > 62 4.24 > 63 9.75 > 64 4.39 > 65 2.90 > 66 6.85 > 67 9.08 > 68 5.54 > 69 6.02 > 70 7.64 > 71 6.85 > 72 0.00 > 73 3.12 > 74 6.75 > 75 4.24 > 76 2.32 > 77 2.58 > 78 2.55 > 79 8.60 > 80 0.00 > 81 0.32 > 82 2.23 > 83 3.98 > 84 6.05 > 85 7.64 > 86 3.03 > 87 0.00 > 88 9.27 > 89 0.00 > 90 0.00 > 91 3.92 > 92 0.00 > 93 20.54 > 94 8.41 > 95 0.00 > 96 2.10 > 97 0.00 > 98 0.00 > 99 13.79 > 100 5.22 > 101 9.43 > 102 6.31 > 103 4.11 > 104 0.00 > 105 0.00 > 106 6.15 > 107 3.41 > 108 14.01 > 109 15.67 > 110 17.20 > 111 20.00 > 112 11.43 > 113 10.35 > 114 10.29 > 115 13.18 > 116 10.61 > 117 0.00 > 118 0.32 > 119 0.00 > 120 7.01 > 121 1.97 > 122 4.52 > 123 19.14 > 124 3.50 > 125 2.99 > 126 3.18 > 127 1.82 > 128 3.18 > 129 6.02 > 130 4.04 > 131 2.61 > 132 2.48 > 133 2.71 > 134 2.68 > 135 1.82 > 136 2.52 > 137 6.72 > 138 2.61 > 139 2.74 > 140 3.15 > 141 3.25 > 142 3.22 > 143 3.44 > 144 4.01 > 145 4.97 > 146 6.15 > 147 9.62 > 148 2.87 > 149 5.83 > 150 17.90 > 151 3.18 > 152 3.54 > 153 2.99 > 154 4.62 > 155 6.85 > 156 0.00 > 157 5.83 > 158 4.49 > 159 2.74 > 160 6.82 > 161 6.82 > 162 4.94 > 163 5.83 > 164 6.02 > 165 0.96 > > -- > View this message in context: > http://r.789695.n4.nabble.com/reading-header-in-txt-file-and-making-histogram-tp4504813p4504813.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.____________________________________________________________ FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
bamboohydraulics
2012-Mar-26 13:56 UTC
[R] reading header in txt file and making histogram
this is what I do, IT READS THE TABLE, But then I am stuck, I removed the header read.table("nigeria slr misc/Nigeria India /DBHHISTOGRAM.txt", header=FALSE) hist("nigeria slr misc/Nigeria India /DBHHISTOGRAM.txt"$V1) Error in "nigeria slr misc/Nigeria India /DBHHISTOGRAM.txt"$V1 : $ operator is invalid for atomic vectors or > hist("nigeria slr misc/Nigeria India /DBHHISTOGRAM.txt",V1) Error in hist.default("nigeria slr misc/Nigeria India /DBHHISTOGRAM.txt", : 'x' must be numeric or with("nigeria slr misc/Nigeria India /DBHHISTOGRAM.txt",hist(V1)) Error in eval(substitute(expr), data, enclos = parent.frame()) : invalid 'envir' argument -- View this message in context: http://r.789695.n4.nabble.com/reading-header-in-txt-file-and-making-histogram-tp4504813p4505886.html Sent from the R help mailing list archive at Nabble.com.
If there is a header in your .txt-file you should have header=TRUE, if there is no header you should have header=FALSE. You have to save your dataset in a variable, for example: myData<-read.table("data.txt",header=TRUE) Then you can make a histogram by: hist(myData) -- View this message in context: http://r.789695.n4.nabble.com/reading-header-in-txt-file-and-making-histogram-tp4504813p4505896.html Sent from the R help mailing list archive at Nabble.com.
Reasonably Related Threads
- interpretation of coefficients in survreg AND obtaining the hazard function for an individual given a set of predictors
- sort list
- interpretation of coefficients in survreg AND obtaining the hazard function
- subset bug?
- Re : interpretation of coefficients in survreg AND obtaining the hazard function for an individual given a set of predictors