r: convert a string to date [duplicate]

We can use sub to create a – between the first 4 characters and the next 2. Match the four characters (.{4}), place it in a capture groups ((…)), followed by the next 2 characters in another capture group, replace it with the backreference for those groups (\\1, \\2) and in between we add the … Read more

Matrix operation in R: I have a square matrix whose determinant is zero, i need to find its inverse in R programing. Is it possible ,if yes how? [closed]

A matrix with determinant 0 does not have an inverse but one can calculate a generalized inverse (also see Moore Penrose inverse) which is not a true inverse but may be useful depending on what you want to do. See the ginv function in the MASS package (which comes with R). M <- matrix(1:9, 3) … Read more

Conversion of a data into time series object

The question’s use of the xts function is incorrect but it doesn’t really matter since xts cannot represent that sort of data in the first place. xts requires an index class that represents dates or date/times such as Date or POSIXct but here we have plain numbers. Create a zoo series instead. library(zoo) # test … Read more

How can i create a contingency table in R? [closed]

You should give a reproducible example. Here some data: set.seed(1234) dat <- data.frame(Smoker=sample(c(‘Smoke’,’No_Smoke’),20,rep=TRUE), CANCER=sample(c(‘Cancer’,’NO_Cancer’),20,rep=TRUE)) Then using table you can get your contingency table: table(dat$Smoker,dat$CANCER) Cancer NO_Cancer No_Smoke 7 4 Smoke 5 4 For more information see ?table Description table uses the cross-classifying factors to build a contingency table of the counts at each combination of … Read more

How to resolve “invalid number of 'breaks'” [closed]

In Python indentation is very important and so are colons. For this you would also want to use a if statement and not a for loop. This code works, age = int(input(“Enter You Age:”)) if age in range (14,18): print (“This student is in Highschool”) else: print (“This student is not in Highschool”)

How to change formats of multiple variables in one dataset?

When importing a .csv file (I assume it is what you did), you must be careful with some stuff: Columns containing numbers are transformed into characters if there is one or more cells marked as #ERROR or #DIV/0 or any other NA strings that have not been clearly mentioned as such. Sometimes, with analytical data, … Read more