When I add something to mydataframe it changes from num. to char. ...

Why does it change to char. after my marked code?

firstname = c("Thomas","Max","Sebi","Jogi","Anna")
lastname = c("Haberl", "Mustermann", "Boehm", "Pfennig", "Mayer")
yearofbirth = c(2000,1995,2000,1999,1992)
agecategory = c("child", "elderly", "adult", "adult", "adolescent")
#3.2
thirdPerson = paste(firstname[3], lastname[3])
#3.3
mydataframe = data.frame(firstname, lastname,yearofbirth,agecategory,stringsAsFactors = FALSE)
#3.4
firstandlastname = paste(mydataframe$firstname,mydataframe$lastname)
#3.5
newMember = c("Franz","Huber",1950,"adult")
#3.6 
mydataframe = rbind.data.frame(mydataframe,newMember,stringsAsFactors = FALSE)

Hello! Welcome to the community.

First I have to admit that without dinner output, it's difficult to understand what is happening. The data looks was expected in the right hand side.

Could you try rbind()instead of rbind.data.frame()? I believe base rbind is less restrictive.

When I add something to mydataframe it changes from num. to char. ...

The something that you are adding is a character vector. A vector is always of a single type, in your case character, the fact you put 1950 as third element can not be relied upon, it gets immediately coerced to "1950"

Still won't work..

#3.1
firstname = c("Thomas","Max","Sebi","Jogi","Anna")
lastname = c("Haberl", "Mustermann", "Boehm", "Pfennig", "Mayer")
yearofbirth = c(2000,1995,2000,1999,1992)
agecategory = c("child", "elderly", "adult", "adult", "adolescent")
#3.2
thirdPerson = paste(firstname[3], lastname[3])
#3.3
mydataframe = data.frame(firstname, lastname,yearofbirth,agecategory,stringsAsFactors = FALSE)
#3.4
firstandlastname = paste(mydataframe$firstname,mydataframe$lastname)
#3.5
newMember = c("Franz","Huber",1950,"adult")
mydataframe = rbind(mydataframe,newMember,stringsAsFactors = FALSE)

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)

Hi, welcome!

Please have a look to our homework policy, homework inspired questions are welcome but they should not include verbatim instructions from your course.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.