R Studio not responding to the names() command - r

I am writing the following below. R studio would send an error message:
Error: unexpected input in "names(mancova)= c(�
in resonse to the line where I give new names to the columns:
names(mancova)= c(“GPID”, “Precomp”, Postcomp”, “Posthior”)
Here is the full code:
install.packages("MASS")
install.packages("car")
install.packages("psych")
install.packages("Rcpp")
library(MASS)
library (car)
library(psych)
group1 = matrix(c(1,15,17,3,1,10,6,3,1,13,13,1,1,14,14,8,1,12, 12, 3, 1, 10, 9, 9,1,12,12,3,1,8,9,12,1,12,15,3,1,8,10,8,1,12,13,1,1,7,11,10,1,12,16,1,1,9,12,2,1,12,14,8), nrow=15,ncol=4, byrow=TRUE)
group2=matrix(c(2,9,9,3,2,13,19,5,2,13,16,11,2,6,7,18,2,10,11,15,2,6,9,9,2,16,20,8,2,9,15,6,2,10,8,9,2,8,10,3,2,13,16,12,2,12,17,20,2,11,18,12,2,14,18,16),nrow=14,ncol=4,byrow=TRUE)
mancova = data.frame(rbind(group1, group2))
names(mancova)= c(“GPID”, “Precomp”, Postcomp”, “Posthior”)
attach(mancova)
mancova
options(scipen=999)
outcome = cbind(mancova$Postcomp, mancova$Posthior)
model = manova(outcome~GPID+Precomp+GPID*Precomp, data=mancova)
summary(model, test=“Wilks”, type=“III”)
factor(GPID)
modelA = aov(Postcomp~Precomp+GPID, data=mancova)
summary(modelA, type=“III”)
library(effects)
adjmeanA = effect(“GPID”, modelA, se=TRUE,xlevels=2)
summary(adjmeanA)
adjmeanA$se

Its written in the error itself:
Error: unexpected input in "names(mancova)= c(�
The last symbol is unknown to R, which is an italic/cursive version of the quotes. " " is defined/valid. " " is not.

Related

Getting error in GDCprepare fuction when using TCGAbiolinks package

I am using TCGAbiolinks package. I have run this code:
coadquery <- GDCquery(project = "TCGA-COAD",
data.category = "Transcriptome Profiling",
data.type ="Gene Expression Quantification",
workflow.type ="STAR - Counts", legacy = F,
experimental.strategy ="RNA-Seq")
GDCdownload(query = coadquery, method = "api")
coadprpr <- GDCprepare(coadquery, summarizedExperiment = T)
but when I run GDCprepare function it gives me error:
|==================================================|100%
Completed after 12 m
Error in `vectbl_as_col_location()`: ! Can't subset columns past the
end. i Locations 2, 3, and 4 don't exist. i There is only 1 column.
Run `rlang::last_error()` to see where the error occurred. There were
50 or more warnings (use warnings() to see the first 50)

Create a dtm using tokens

I try to run tis command
dtm <- CreateDtm(tokens$text,
doc_names = tokens$ID,
ngram_window = c(1, 2))
However I receive this error:
Error in seq.default(1, length(tokens), 5000) :
wrong sign in 'by' argument
In addition: Warning message:
In CreateDtm(tokens$text, doc_names = tokens$ID, ngram_window = c(1, :
No document names detected. Assigning 1:length(doc_vec) as names.
Any idea what I have to change in order to run it properly?

Error appearing while running R code: no 'dimnames' attribute for array

I am trying to predict outcomes using. neuralnetwork. I am using the r package neuralnet, and when running the following code, I receive the error:
library(neuralnet)
new.output = compute(nn1, covariate=matrix(c(0,0,0,0,1,0,0,1,0,0,
0,0,0,0,1,0,1,0,0,0,
0,0,0,0,1,1,0,0,0,0,
0,0,0,1,0,0,0,0,0,1,
0,0,0,1,0,0,0,0,1,0,
0,0,0,1,0,0,0,1,0,0,
0,0,0,1,0,0,1,0,0,0,
0,0,0,1,0,1,0,0,0,0,
0,0,1,0,0,0,0,0,0,1,
0,0,1,0,0,0,0,0,1,0,
0,0,1,0,0,0,0,1,0,0,
0,0,1,0,0,0,1,0,0,0,
0,0,1,0,0,1,0,0,0,0,
0,1,0,0,0,0,0,0,0,1,
0,1,0,0,0,0,0,0,1,0,
0,1,0,0,0,0,0,1,0,0,
0,1,0,0,0,0,1,0,0,0,
0,1,0,0,0,1,0,0,0,0,
1,0,0,0,0,0,0,0,0,1,
1,0,0,0,0,0,0,0,1,0,
1,0,0,0,0,0,0,1,0,0,
1,0,0,0,0,0,1,0,0,0,
1,0,0,0,0,1,0,0,0,0), nrow = 23, ncol = 10))
Error in newdata[, object$model.list$variables] : no 'dimnames'
attribute for array
What could be causing this? I have done this before with more rows and columns and it worked perfectly.
Thank you in advance!

Error creating multiple heatmaps with ComplexHeatmap package

I am having difficulty with creating multiple heatmaps with the ComplexHeatmap package. When I run a script that contains code exactly lifted from the documentation (https://bioconductor.org/packages/release/bioc/vignettes/ComplexHeatmap/inst/doc/s3.a_list_of_heatmaps.html)...
library(ComplexHeatmap)
mat1 = matrix(rnorm(80, 2), 8, 10)
mat1 = rbind(mat1, matrix(rnorm(40, -2), 4, 10))
rownames(mat1) = paste0("R", 1:12)
colnames(mat1) = paste0("C", 1:10)
mat2 = matrix(rnorm(60, 2), 6, 10)
mat2 = rbind(mat2, matrix(rnorm(60, -2), 6, 10))
rownames(mat2) = paste0("R", 1:12)
colnames(mat2) = paste0("C", 1:10)
ht1 = Heatmap(mat1, name = "ht1")
ht2 = Heatmap(mat2, name = "ht2")
class(ht1)
class(ht2)
ht1 + ht2
... I get the error message:
Error in ht1 + ht2 : non-numeric argument to binary operator
Execution halted
I am running R version 3.3.2 (2016-10-31) -- "Sincere Pumpkin Patch" on Mac OS X 10.12.2 with ComplexHeatmap version 1.12.0. Thank you for any help!
I figured it out. The problem was that the "methods" package needs to be attached. If you run the above code directly in R (which I was NOT doing), it works as-is (becuase R apparently loads the methods package by default), but if you have the script in a file and run it via Rscript (which is what I WAS doing), you get the indicated error. However, If you add
library(methods)
to the top of the script, it works via Rscript.

Error: object not found - cor.ci

I'm trying to use cor.ci to obtain polychoric correlations with significance tests, but it keeps giving me an error message. Here is the code:
install.packages("Hmisc")
library(Hmisc)
mydata <- spss.get("S-IAT for R.sav", use.value.labels=TRUE)
install.packages('psych')
library(psych)
poly.example <- cor.ci(mydata(nvar = 10,n = 100)$items,n.iter = 10,poly = TRUE)
poly.example
print(corr.test(poly.example$rho), short=FALSE)
Here is the error message it gives:
> library(psych)
> poly.example <- cor.ci(mydata(nvar = 10,n = 100)$items,n.iter = 10,poly = TRUE)
Error in cor.ci(mydata(nvar = 10, n = 100)$items, n.iter = 10, poly = TRUE) :
could not find function "mydata"
> poly.example
Error: object 'poly.example' not found
> print(corr.test(poly.example$rho), short=FALSE)
Error in is.data.frame(x) : object 'poly.example' not found
How can I make it recognize mydata and/or select certain variables from this dataset for the analysis? I got the above code from here:
Polychoric correlation matrix with significance in R
Thanks!
You have several problems.
1) As previously commented upon, you are treating mydata as a function, but you need to treat it as a data.frame. Thus the call should be
poly.example <- cor.ci(mydata,n.iter = 10,poly = TRUE)
If you are trying to just get the first 100 cases and the first 10 variables, then
poly.example <- cor.ci(mydata[1:10,1:100],n.iter = 10,poly = TRUE)
2) Then, you do not want to run corr.test on the resulting correlation matrix. corr.test should be run on the data.
print(corr.test(mydata[1:10,1:100],short=FALSE)
Note that corr.test is testing the Pearson correlation.

Resources