1

I'm trying to fix the NA problem and trying to dot plot the data frame from ".CSV" file.

I'm trying to get the mean median and 10% trimmed mean of the given data frame, somehow I'm getting an error. I have already tried previous suggestions and still not helping me out. I have data and I can't plot the dot chart from it.

code for mean median and 10% trimmed mean

data_val <- read.csv(file = 
"~/502_repos_2019/502_Problems/health_regiment.csv", head=TRUE, sep 
= " ")
as.numeric(unlist(data_val))

print(ncol(data_val))
print(nrow(data_val))

# I have used several logics but it's not helping to solve the problem
mean(data_val,data_val$cholesterol_level[data_val$Treatment_type == 
'Control_group'])
mean(data_val$cholesterol_level[data_val$Treatment_type == 
'Treatment_group'])

code for dot chart & dot plot

data_val <- read.csv(file = 
"~/502_repos_2019/502_Problems/health_regiment.csv", head=TRUE, sep 
= " ")
data_val

plot(data_val$Treatment_type ~ data_val$cholestrol_level, xlab = 
"Health Unit Range", ylab = " ", 
    main = "Regiment_Health", type="p") #p for point chart 


#dotchart(data_val, data_val$Treatment_type ~ 
data_val$cholestrol_leve, labels = row.names(data_val),
#cex = 0.6,xlab = "units") 

Following is the error message

[2] 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 7 3 -4 14 2 5 22 -7 9 5 -6 5 9 4 4 12 37 [38] 5 3 3 [2] 2 [2] 20 argument is not numeric or logical: returning NA[2] NA argument is not numeric or logical: returning NA[2] NA

and instead of point plot, I'm getting bar chart and dot chart syntax is not working though I have given the proper syntax.

enter image description here

.csv data

Treatment_type cholestrol_level
Control_group 7
Control_group 3
Control_group -4
Control_group 14
Control_group 2
Control_group 5
Control_group 22
Control_group -7
Control_group 9
Control_group 5
Treatment_group -6
Treatment_group 5
Treatment_group 9
Treatment_group 4
Treatment_group 4
Treatment_group 12
Treatment_group 37
Treatment_group 5
Treatment_group 3
Treatment_group 3

Data in dput format.

data_val <-
structure(list(Treatment_type = structure(c(1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L), .Label = c("Control_group", "Treatment_group"), 
class = "factor"), cholestrol_level = c(7L, 3L, -4L, 14L, 
2L, 5L, 22L, -7L, 9L, 5L, -6L, 5L, 9L, 4L, 4L, 12L, 37L, 
5L, 3L, 3L)), class = "data.frame", row.names = c(NA, -20L))
Nick Reed
  • 4,989
  • 4
  • 17
  • 37
Mayur Potdar
  • 451
  • 1
  • 8
  • 18
  • 2
    Please provide reproducible data and specify which part of the code is producing the error – IceCreamToucan Sep 06 '19 at 18:10
  • I believe that what you need is `mean(data_val$cholesterol_level[data_val$Treatment_type == 'Treatment_group'], na.rm=T)` – G5W Sep 06 '19 at 18:15
  • @G5W I have tried your solution, it's still showing NA – Mayur Potdar Sep 06 '19 at 18:19
  • I have stored the .csv data frame itself in a data_val variable, I can see the result that data is there and there is no way I can add the actual file from my end – Mayur Potdar Sep 06 '19 at 18:30
  • Seems like your numeric variable is not numeric, maybe it's a factor. Post the output of `dput(data_val)` instead. – Rui Barradas Sep 06 '19 at 18:44
  • @RuiBarradas have tried your suggestion and following is the answer structure(list(Treatment_type = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Control_group", "Treatment_group"), class = "factor"), cholestrol_level = c(7L, 3L, -4L, 14L, 2L, 5L, 22L, -7L, 9L, 5L, -6L, 5L, 9L, 4L, 4L, 12L, 37L, 5L, 3L, 3L)), class = "data.frame", row.names = c(NA, -20L)) – Mayur Potdar Sep 06 '19 at 18:50
  • 1) Remove the tilde, separate the coordinates with a comma. 2) In base R you will have a boxplot unless you `plot(as.integer(data_val$Treatment_type), data_val$cholestrol_level, etc)`. 3) Load `library(ggplot2)` and then `ggplot(data_val, aes(Treatment_type, cholestrol_level)) + geom_point()`. – Rui Barradas Sep 06 '19 at 19:00
  • @RuiBarradas Thank you for clarification in the code. I'm still trying to get mean median and 10% trimmed mean from .csv file – Mayur Potdar Sep 06 '19 at 19:12
  • @G5W I'm trying following code for medianmedian(data_val$cholesterol_level[data_val$Treatment_type == 'Control_group']) median(data_val$cholesterol_level[data_val$Treatment_type == 'Treatment_group']) its still showing NULL as a result – Mayur Potdar Sep 06 '19 at 20:49
  • @RuiBarradas I'm trying following code for medianmedian(data_val$cholesterol_level[data_val$Treatment_type == 'Control_group']) median(data_val$cholesterol_level[data_val$Treatment_type == 'Treatment_group']) its still showing NULL as a result – – Mayur Potdar Sep 06 '19 at 20:50
  • `aggregate(cholestrol_level ~ Treatment_type, data_val, mean)` or `tapply(data_val$cholestrol_level, data_val$Treatment_type, mean)`. [duplicate](https://stackoverflow.com/questions/21982987/mean-per-group-in-a-data-frame). – Rui Barradas Sep 06 '19 at 22:02

0 Answers0