[英]Making a histogram
這聽起來很基本,但每次我嘗試制作直方圖時,我的代碼都說 x 需要是數字。 我到處找,但找不到與我的問題有關的。 我有 240 個 obs 和 5 個變量的數據。
Nipper length
Number of Whiskers
Crab Carapace
Sex
Estuary location
有 3 個位置,我正在嘗試使用鉗子長度制作直方圖
我嘗試制作新的因素和級別,每個位置都有 80 個 obs,但它不起作用
Crabs.data <-read.table(pipe("pbpaste"),header = FALSE)##Mac
names(Crabs.data)<-c("Crab Identification","Estuary Location","Sex","Crab Carapace","Length of Nipper","Number of Whiskers")
Crabs.data<-Crabs.data[,-1]
attach(Crabs.data)
hist(`Length of Nipper`~`Estuary Location`)
hist.default 中的錯誤(
Length of Nipper
~Estuary Location
):'x' 必須是數字
而不是正確的結果
hist() 似乎不喜歡采用多個變量。
我認為您最好能將數據子集化,即為給定河口中的所有螃蟹制作一個鉗子長度向量。
crabs.data<-read.table("whatever you're calling it")
names<-(as you have it)
Estuary1<-as.vector(unlist(subset(crabs.data, `Estuary Loc`=="Location", select = `Length of Nipper`)))
hist(Estuary1)
對其他兩個河口重復最后兩行。 您可能不需要 unlist() 命令,具體取決於您的表。 我傾向於將它用於 Excel 文件,但我不知道您的表格采用什么格式(這會有所幫助)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.