BSebi
April 10, 2021, 12:46pm
1
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"
BSebi
April 11, 2021, 12:39pm
5
(post withdrawn by author, will be automatically deleted in 24 hours unless flagged)
BSebi
April 11, 2021, 12:39pm
6
(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.
Can I ask questions from a course I am taking here?
General questions are always welcome!
Please do ask general questions about things like:
How to use R
How to use the RStudio IDE or RStudio Cloud
How to work with tidyverse packages
Where to find resources to help you learn or solve problems
Specific questions can be OK, if you follow these rules:
Never copy-paste instructions from an assignment (even for online courses).
Explicitly mention the course you are taking and use the #homework tag.
Ask your question as a reproducible example (reprex) , preferably prepared for posting using the reprex package .
Want to maximize your chances of getting the help you need? Keep readin…
system
Closed
May 2, 2021, 12:43pm
8
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.