R programming error

0 votes

I'm a newbee to R, I'm not very clear with the basics.Here is a character vector:

longString <- "ggstyle<-function(inputFile {tableMedian=inputFile#plotstyleroutine#thislinesolvestheproblemifthemedianofevennumberofdaysistakenbytakingthevectornumberdayMedVec=round(length(unique(tableMedian$day))/2,0)dayMed=as.numeric(unique(tableMedian$day)[dayMedVec])x=tableMedian[tableMedian$day==dayMed,]p=ggplot(x,aes(x=AGE,y=SCORES))+geom_bar(stat=\"identity\",alpha=1)print(p)}"

I require a logic to grab:

ggstyle(inputFile)

My idea was to grab everything before

<-function as the first vector and everything between function() as a second vector and then finally, combine the two vectors.

But I don't know how to make this work? Any help would be appreciated

Dec 18, 2018 in Data Analytics by Sophie may
• 9,850 points
28 views

1 answer to this question.

0 votes

Alright, you can either use gsub to match the substring you want to delete and instead replace it with ''

gsub("[[:punct:]]+function|\\{.*", "", longString)
 "ggstyle(inputFile)"

Or grab the group of strings and replace it with the backreference

sub("^([[:alpha:]]+)[[:punct:]]+[[:alpha:]]+([^)]+\\)).*", "\\1\\2", longString)
 "ggstyle(inputFile)"
answered Dec 18, 2018 by Tyrion anex
• 8,270 points

Related Questions In Data Analytics

0 votes
2 answers

Error: could not find function - R Programming

Yes, Just like @Maverik said, It happens ...READ MORE

answered Aug 22 in Data Analytics by anonymous
• 31,840 points
4,667 views
0 votes
1 answer

"no applicable method" Error in r programming

This is caused by using an object-oriented ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 41,990 points
97 views
0 votes
1 answer

“subscript out of bounds” Error in r programming

This error is likely to occur when ...READ MORE

answered Oct 31, 2018 in Data Analytics by Kalgi
• 41,990 points
2,046 views
0 votes
1 answer

R programming: Missing value error

You can achieve this by wrapping isTRUE() around your if-condition: for ...READ MORE

answered Jan 24 in Data Analytics by Sophie may
• 9,850 points
79 views
0 votes
1 answer

R programming: Unexpected symbol error

Format your code this way: myfunction <- function() ...READ MORE

answered Dec 17, 2018 in Data Analytics by Sophie may
• 9,850 points
300 views
0 votes
1 answer

R Programming error in 'fert'

You're using a factor: fert <- factor(c(50,20,10,10,20,50)) levels(fert) #[1] ...READ MORE

answered Dec 27, 2018 in Data Analytics by Sophie may
• 9,850 points
49 views
0 votes
1 answer

R Programming: Market Basket Analysis Error

The basket.sorted() has less than 5 rules. Refer ...READ MORE

answered Feb 11 in Data Analytics by Sophie may
• 9,850 points
148 views
0 votes
1 answer

R Programming: regexpr error

The below code will help: gregexpr("D", x) # [[1]] # ...READ MORE

answered Feb 21 in Data Analytics by Tyrion anex
• 8,270 points
29 views
0 votes
1 answer

R Programming error: twitteR OAuthFactory object

You need to install the following packages: install.packages(c('ROA ...READ MORE

answered Jan 11 in Data Analytics by Tyrion anex
• 8,270 points
93 views
0 votes
2 answers

R Programming error in if condition

Hi. Instead of breaking the line add it ...READ MORE

answered Aug 26 in Data Analytics by anonymous
• 31,840 points
62 views