I am trying to use dcast() to change a long format data into a wide format data. I am using the data frame "airquality" that is built into R.
When I run the code below, I get this error message:
Error in eval(expr, envir, enclos) : object 'variable' not found.
I have tried to search for an answer here but I have not seen one that is specific to the function dcast().
airquality_cast1 <- dcast(airquality, month + day ~ variable)
I see that the problem is with the last bit of the code, but I can't seem to figure out what it is. Was I supposed to assign variable to some object before running this code? Or is there some package I need to install for this to work?
Thank you!
Related
I am trying to filter a dataset in R. I have installed (dplyr) package. I keep getting an error message that the column i am trying to filter cannot be found. I have checked the dataset name for spelling errors as well as the column name. I can clearly see the column "dose" in the dataset. I was expecting the dataset to be filtered according to the codeCan someone please help? I will share the code below and the error message.
data("ToothGrowth")
View (ToothGrowth)
filtered_ToothG <- filter(ToothGrowth,dose==0.5)
View (filtered_ToothG)
Error in filter(ToothGrowth, dose == 0.5) : object 'dose' not found
So I am trying to run the section of code
library(ARTool)
attach(salix.dat)
removal.art <- art(logSumSalix ~ as.factor(NewCode) + (1|Reach))
anova(removal.art)
and I keep getting the error message
Error in list2env(data) : first argument must be a named list
From what I have read in previous post you need to convert the data you are using into a data frame but I tried that and it produced the exact same error message. Does anyone know a work around for this problem?
I am new to R and to actually asking a question in Stack Overflow. I looked at several similar questions, but they did not seem to apply to help my situation. I am trying to make a linear model with the lm() function, but I get an error returned that states one of my data frame columns is able to be found:
library(SemiPar) # Contains Janka data
data(janka)
names(janka) <- c("Density", "Hardness")
janka.ls1 <- lm(hardness~dens, Data = janka)
I get the following error after running the final line:
Error in eval(predvars, data, env) : object 'Hardness' not found
As you can see, I named one of the two columns 'Hardness' and when I view the data I also see that the names do match. Further, when I try running the code using the original data column name, it still has the same issue.
Thanks for your help!!
We have always been an SPSS shop but we're trying to learn R. Been doing some basics. I am trying to do a simple t-test, just to learn that code.
Here's my code, and what's happening:
Code screenshot
I don't get why it says "score" isn't found. It's in the table, and the read.csv code defaults to assuming the first row contains headers. I can't see why it's not "finding" the column for score. I'm sure it's something simple, but would appreciate any help.
You didn't store your imported csv file in a variable. It printed to the console because it had nowhere else to go - it just gets printed and then thrown away. You need to assign it for it to be saved in memory:
my_data_frame <- read.csv("ttest.csv")
Now your data exists in the variable my_data_frame and you can use it by supplying it as the data argument:
t.test(score ~ class, mu=0, alt="two.sided", conf=0.95, var.eg=F, paired=F, data=my_data_frame)
Also, in general, I would recommend using read_csv from the package readr over the default read.csv - it's faster.
Finally, when you ask questions, please provide your code as text, not a picture. You should also provide your data or a toy dataset - you can use the function dput to print code that will create your data, or just provide the csv file or some code that creates toy data.
I'm Trying to do a simple linear regresion by calling a .CSV file where i have 14 different variables...which were first in a Excel file.
In Excel i named the variables by just putting a name above the data, but i don't really believe that means that that names the whole column by that variable.
(Of course i first call the .CSV file from R:
> datos<-read.table("datos3.csv",header=T,sep=";",dec=",")
So that must be why when i call them by name in R like:
regresion<-lm(RM~MEDV)
R says: Error in eval(expr, envir, enclos) : object 'RM' not found
The thing i find strange is that when i change the order of the variables (say MEDV~RM) i get the same error but saying that MEDV was not found this time. Is it because is the first thing it reads and detects?
Is there a way from Excel or R that i can name the variables for me to call them without errors or is the problem anywhere else?
UPDATED CODE
rm(list=ls())
datos<-read.table("datos3.CSV",header=T,sep=";",dec=",")
View(datos)
regresion<-lm(MEDV,RM,data=datos)
After this i get
Error in stats::model.frame(formula = MEDV, data = datos, subset = RM, :
object 'MEDV' not found
Basically the problem is that since i was using first an excel file for my data, i had the variables named included in the first row, so when passing it to .CSV format and trying to read it in R, it transformed those characters into data as factors. So when trying to do a regresion it did not have only number values.
After that it was the "dec"argument in the read.csv causing trouble and printing the same error. So after removing that and typing:
datos <- read.csv("datos3.csv")
I had no trouble making the regresion and could analyze the data i wanted.
(special thanks to #user20650 for helping me out)