How to change the datatype of any field in an external dataset in R

0 votes
How to change the datatype of any field in an external dataset in R?
Jun 28, 2019 in Data Analytics by Anand
736 views

1 answer to this question.

0 votes
Hi Anand,

Try as below -

class(dataset/dataframe$col_name) <- "data type"

For Ex: Below code would change the datatype of Sepal. Length to an integer.

data = datasets::iris

class(data$Sepal.Length) <- "integer"

Here new data type should be given that can take the domain of already existing elements in the column.

Such as Numeric -> integer/character but the reverse is not always possible.

Check the validity of the datatype and accordingly change the datatype.
answered Jun 28, 2019 by anonymous
• 33,030 points

Related Questions In Data Analytics

+1 vote
1 answer

Is it possible to change the column names of the dataset that I'm using in R?

That is definitely possible in R. You ...READ MORE

answered Dec 17, 2018 in Data Analytics by Anisha

edited Dec 17, 2018 1,669 views
0 votes
1 answer

How can I control the size of points in an R scatterplot?

plot(variable, type='o' , pch=5, cex=.3) The pch argument ...READ MORE

answered May 3, 2018 in Data Analytics by shams
• 3,670 points
1,253 views
0 votes
1 answer

How to write a custom function which will replace all the missing values in a vector with the mean of values in R?

Consider this vector: a<-c(1,2,3,NA,4,5,NA,NA) Write the function to impute ...READ MORE

answered Jul 4, 2018 in Data Analytics by CodingByHeart77
• 3,750 points
4,515 views
0 votes
1 answer

How to reduce the height of valueBox in shiny R?

Add this line before using your vlaueBoxes tags$head(tags$style(HTML(".small-box ...READ MORE

answered Dec 4, 2018 in Data Analytics by Haseeb
3,986 views
0 votes
1 answer

By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
2,219 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,882 views
0 votes
1 answer

In a dpylr pipline how to use sample and seq?

For avoiding rowwise(), I prefer to use ...READ MORE

answered Apr 6, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 9, 2020 by Gitika 1,143 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,287 views
+1 vote
3 answers

How to change the value of a variable using R programming in a data frame?

Try this: df$symbol <- as.character(df$symbol) df$symbol[df$sym ...READ MORE

answered Jan 11, 2019 in Data Analytics by Tyrion anex
• 8,700 points
35,749 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP