Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to pass a data frame to a function as an argument. And then inside the function, I want to work on different combinations of columns for graphical presentation. Basically, I want to do graphical presentation on different data files. I want that, I pass the data file as an argument and then get the graphs. How can I do this in R.
You are not giving us much info but here is a very basic starting point:
library(ggplot2) # if you don't have this library run install.packages('ggplot2')
myAmazingFunction <- function(myDF) {
ggplot(myDF,aes(X,Y))+geom_line()
}
df <-data.frame(X=1:30, Y=runif(30), Z=1.3*runif(30))
myAmazingFunction(df)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
can anyone explain to me the tsSmooth function in R?
I would like to use it to obtain a univariate time series with a linear trend
Please note that on your code:
x<-rt(n=30,df=3, ncp=10)
y<-rt(n=20,df=3,ncp=20)
myseries<-c(x,y)
tsSmooth<-c(x,y)
newseries<-tsSmooth
you didn't apply the tsSmooth() function to your data. You simply created a vector named tsSmooth and another vector named newseries
tsSmooth() function uses a specific data input and doesn't provide much explanation.
There is this discussion that might help https://stats.stackexchange.com/questions/125946/generate-a-time-series-comprising-seasonal-trend-and-remainder-components-in-r
In addition, you could generate a simple trend using moving average. But I am not sure if it has all the statistical features you are looking for.
library("TTR")
plot.ts(myseries)
trendSMA <- SMA(myseries)
plot.ts(trendSMA)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
I have imported a pimadata.csv to R, I have to create a scatter plot matrix for the first 8 columns in the pimadata; also have to find two variables that seem to have positive correlations. I used this line of code to create the plot;
pairs(pimadata[,1:8])
What should I do to show the correction between the variables?
You could use cor()
cor(pimadata[,1:8])
Since you did not provide the contents of pimadata.csv, I use the iris dataset as an example here.
head(iris)
pairs(iris[,1:4])
scatter plot
cors <- cor(iris[,1:4])
correction output
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I need to write a function in R, since in other languages like c++ it works very slow. The function fills a 2d table with data, and then summarizes values of each row for further processing.
I am not sure if it answers your question, but if you work with data you can put them into data frames to take a look at the statistical parameters and for further processing. For example:
df = data.frame("var1" = c(5,10,15), "var2" = c(20,40,60))
#the 'summary' command gives you some statistical parameters based on the column
summary(df)
#with the 'apply' command you can addresses the rows.
#in this example you get the mean of each row:
apply(df, 1,mean)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have written the following code to compare Two Market, the code is working if we provide the Data Frame name individually.
enter image description here
for(i in 1:nrow(Market_SystemA))
{
A <- Market_SystemA[i,2]
B <- Market_SystemB[i,3]
MarketA <- data.frame(A)
MarketB <- data.frame(B)
#This is s fuction in R
Compare_Function(MarketA,MarketB)
}
I'm not sure if I understand your question correctly, but it seems like you are calling a compare_function on two strings that refer to existing data frames. To actually get the data frames from the string, then you will need to use the get function which looks for an object that has a name that matches the string.
MarketA <- get(A)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I would like to classify pictures by using R software. I have no knowledge in image processing so it will be great if someone would point me to the right direction. First, how can I turn a picture that I have into a structured dataframe so I'll be able to analyze it? Is there a package for this task? Second, Is there a defined process for picture classification that I can follow?
With this lines you can load images in R and store them in a list.
library(jpeg)
setwd("path/to/folder/with/images/")
pics <- dir()
all_images <- NULL
for(z in pics){
all_images[[z]] <- readJPEG(z, native = T)
}
# check the first image in the list
plot(1:2, type='n')
rasterImage(all_images[[1]],1,1,2,2)
for processing images you can use the imager package.